c# 数据库加入的时候为什么不能加入!!!在线等!请各位给看看!
初学数据库 请各位给看看!谢谢!
下面是对数据库操作的代码:
OleDbConnection mySql;
OleDbDataAdapter myDa;
DataSet myDs;
mySql = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=northwind.mdb;User Id=;Password=");
mySql.Open();
string str1 = "SELECT * FROM 客户";
myDa = new OleDbDataAdapter();
OleDbCommand myCmd = new OleDbCommand(str1, mySql);
Source=northwind.mdb;User Id=;Password=");
myDa.SelectCommand = myCmd;
myDs = new DataSet();
myDa.Fill(myDs,"客户");
DataTable dataTable = myDs.Tables[0];
DataRow newRow = dataTable.NewRow();
newRow["作者"] = textBox1.Text;
newRow["书名"] = textBox2.Text;
try
{
int age = int.Parse(textBox3.Text);
newRow["年龄"] = age;
}
catch { }
dataTable.Rows.Add(newRow);
myDs.AcceptChanges();
myDa.Update(myDs, "客户");
mySql.Close();
myDa.MissingMappingAction = MissingMappingAction.Error;
myDa.MissingSchemaAction = MissingSchemaAction.Error;