對oracle資料庫 串連,增,刪,改,查操作的範例程式碼
1樓
MyConn = New System.Data.OleDb.OleDbConnection("Provider=MSDAORA.1;Data Source=oracle9;User ID=test;Password=test;")
2)定義並執行命令
Me.cmdinsert = New System.Data.OleDb.OleDbCommand()
'定義並設定命令的屬性。
Me.cmdinsert.CommandText = "insert into table(name,old,nation) values('" & Me.Tname.Text & "'," & "to_date('" & Me.Told.Text & "','dd/mm/yy')" & ",'" & Me.Tnation.Text & "')"
Me.cmdinsert.CommandType = CommandType.Text
Me.cmdinsert.Connection = Me.MyConn
'開啟資料庫連接
Me.MyConn.Open()
'調用ExecuteNonQuery命令,執行無傳回值的insert命令。
Me.cmdinsert.ExecuteNonQuery()
Me.MyConn.Close()
2 樓
(1)串連
string strconn = "data source=source;user=sa;password=sa;";
OracleConnection myConnection = new OracleConnection(strconn);
myConnection.Open();
(2)
string strsel = "select * from table_name";
or strsel = "insert into table(id,name) values('1','23')";
or strsel = "delete from table where id='1'";
OracleCommand mycom = new OracleCommand(strsel,myConnection);
mycom.ExecuteNonReader();
myConnection.Close();
3 樓lanyahuhu(寶姐姐和林妹妹,兩個我都喜歡(補鈣中))回複於 2003-10-17 09:20:29 得分 0 行
26:string sConn = System.Configuration.ConfigurationSettings.AppSettings["DbConn"];
行 27: m_Conn=new OleDbConnection(sConn);
行 28: m_Conn.Open();
報錯如下 :
異常詳細資料: System.Data.OleDb.OleDbException: 拒絕訪問。
4 樓chinanewway(新路了無痕)回複於 2003-10-17 09:32:55 得分 0 我知道的,要麼你的資料庫不是信任連接,你就必須寫上
user id和password,這樣才能訪問資料庫;或者是你的oracle資料庫服務未啟動。
5 樓chinanewway(新路了無痕)回複於 2003-10-17 09:37:27 得分 0 在web.config檔案中可以加入索引值如下:
<appSettings>
<add key="oleDbConnection.ConnectionString" value="packet size=4096;user id=lamis;password=lamis;data source="LAMIS-SERVER";provider=SQLOLEDB;persist security info=False;initial catalog=lamis;workstation id=SOSORE" />
<add key="strConnection" value="data source=LAMIS-SERVER;initial catalog=lamis;persist security info=False;user id=lamis;password=lamis;workstation id=CXQ;packet size=4096" />
</appSettings>