當前位置:編程學習大全網 - 行動軟體 - C#連接DB2數據庫的方法和代碼

C#連接DB2數據庫的方法和代碼

OleDbConnection1.Open();

//打開數據庫連接

OleDbDataAdapter1.Fill(dataSet1,"Address");

//將得來的數據填入dataSet

DataGrid1.DataBind();

//綁定數據

OleDbConnection1.Close();

//關閉連接

//增加數據庫數據

在Web Form上新增對應字段數量個數的TextBox,及壹個button,為該按鍵增加Click響應事件代碼如下:

this.OleDbInsertCommand1.CommandText = "INSERTsintosADDRESS(NAME,

EMAIL, AGE, ADDRESS) VALUES

('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')";

OleDbInsertCommand1.Connection.Open();

//打開連接

OleDbInsertCommand1.ExecuteNonQuery();

//執行該SQL語句

OleDbInsertCommand1.Connection.Close();

//關閉連接

  • 上一篇:1920x1080動漫壁紙死神
  • 下一篇:湖南衡陽天氣預報
  • copyright 2024編程學習大全網