//进行添加记录
OleDbDataAdapter adapter = new OleDbDataAdapter(strSQL,strCN) ;//创建填充DataSet的对象Adapter
OleDbCommandBuilder cb = new OleDbCommandBuilder (adapter);
cb.QuotePrefix = "[";
cb.QuoteSuffix = "]";
DataSet dataset = new DataSet ();
adapter.Fill (dataset,"acUser");//用表User填充dataset对象
DataRow newRow = dataset.Tables["acUser"].NewRow ();
newRow["acUserID"]="abcd";
dataset.Tables["acUser"].Rows.Add (newRow);
adapter.Update (dataset,"acUser");
***********************************************************************************
在BUTTON的Click事件里添加:
string MainNumber = txtMainNumber.Text;
string CreateDate = cobYear.Text + "年" + cobMonth.Text + "月" + cobDay.Text + "日";
string EntrustUnit = cobUnit.Text;
string insertCmd = "INSERT INTO Try VALUES('MainNumber','CreateDate','EntrustUnit')";
String connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Vehicle.mdb";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand(insertCmd,conn);
conn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("数据成功添加");
阅读(5170) | 评论(0) | 转发(0) |