conObj = new OleDbConnection();
conObj.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=d:\My Documents\db1.mdb";
try
{
conObj.Open();
string str = "Insert into students values ('" + textBox1 + "','" + textBox2 + "','" + textBox3 + "','" + textBox4 + "')";
string strSelect = "Select*from students";
this.cmdObj = new OleDbCommand(str, conObj);
adObj = new OleDbDataAdapter(strSelect, conObj);
adObj.InsertCommand = cmdObj;
DataSet setObj = new DataSet();
adObj.Fill(setObj, "students");
DataTable tableObj = setObj.Tables[0];
DataRow newRow = tableObj.NewRow();
newRow["学生编号"] = textBox1.Text;
newRow["名字"] = textBox2.Text;
newRow["学历"] = textBox3.Text;
newRow["电话号码"] = textBox4.Text;
tableObj.Rows.Add(newRow);
adObj.Update(setObj, "students");
setObj.AcceptChanges();
MessageBox.Show("保存成功");
}
为什么我插入的数据11111 而真正插入数据库中的是System.Windows.Forms.TextBox, Text: 11111 呢 这System.Windows.Forms.TextBox, Text: 都是什么啊?
我该怎么改啊?