首先要寫連接字串
可以在web.config裡寫上
複製代碼 代碼如下:<connectionStrings>
<add name="oracleson" connectionString="Data Source=dingsenorcl;Persist Security Info=True;User ID=ds;Password=ds;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
<connectionStrings>
<add name="oracleson" connectionString="Data Source=dingsenorcl;Persist Security Info=True;User ID=ds;Password=ds;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
然後再後台調用複製代碼 代碼如下:string orclcon = ConfigurationManager.ConnectionStrings["oracleson"].ConnectionString;
string orclcon = ConfigurationManager.ConnectionStrings["oracleson"].ConnectionString;
然後要建立一個資料庫連接對象
複製代碼 代碼如下:OracleConnection conn = new OracleConnection(orclcon)
OracleConnection conn = new OracleConnection(orclcon)
建立一個OracleCommand對象來對資料庫進行操作複製代碼 代碼如下:OracleCommand cmd = conn.CreateCommand()
OracleCommand cmd = conn.CreateCommand()開啟串連
conn.Open();操作就行了
複製代碼 代碼如下:cmd.CommandText = "insert into T_12(AAAA)values(:a)";
cmd.Parameters.AddWithValue(":a", TextBox1.Text); //參數替換oracle資料庫要用: sqlserver資料庫是@
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into T_12(AAAA)values(:a)";
cmd.Parameters.AddWithValue(":a", TextBox1.Text); //參數替換oracle資料庫要用: sqlserver資料庫是@
cmd.ExecuteNonQuery();