首先要寫連接字符串
可以在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();