C# 将新数据插入access
我想在oledb中插入一行新数据。我只是简单地用更新的方式构建代码。但是,OleDbCommand ins=new-OleDbCommandinsertString、strOleDbConnectionString存在错误 如果不使用TableAdapter或参数等,它实际上是如何工作的C# 将新数据插入access,c#,insert,oledb,C#,Insert,Oledb,我想在oledb中插入一行新数据。我只是简单地用更新的方式构建代码。但是,OleDbCommand ins=new-OleDbCommandinsertString、strOleDbConnectionString存在错误 如果不使用TableAdapter或参数等,它实际上是如何工作的 string strOleDbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Project.mdb"
string strOleDbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Project.mdb";
OleDbConnection objConnection = new OleDbConnection(strOleDbConnectionString);
string insertString = "INSERT INTO jiahe ([Tag ID], User, Age, [Phone Number]) VALUES (123, Esther, 19, 92786618)";
string newTagID = textBox1.Text;
string newUser = textBox2.Text;
string newAge = textBox3.Text;
string newPhoneNumber = textBox4.Text;
OleDbCommand ins = new OleDbCommand(insertString, strOleDbConnectionString);
ins.Connection.Open();
ins.ExecuteNonQuery().ToString();
ins.Connection.Close();
看起来像是查询中的一个简单错误 如果用户是一个字符串,但不知道其余部分,则应简单地引用它
"INSERT INTO jiahe ([Tag ID], User, Age, [Phone Number]) VALUES (123, 'Esther', 19, 92786618)"
此外,oledbcommand接收连接对象,而不是连接字符串。试一试
OleDbCommand ins = new OleDbCommand(insertString, objConnection );
以斯帖不应该是单身的吗?