我无法将数据插入Microsoft Access
数据库。以下是我的代码:
roomTableAdapter.Connection.Open();
string s = "INSERT INTO `room` ([number], [priceroom]) VALUES (@param1,@param2)";
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(s, roomTableAdapter.Connection);
cmd.Parameters.AddWithValue("@param1", textBoxX4.Text);
cmd.Parameters.AddWithValue("@param2", "4000");
roomTableAdapter.Adapter.InsertCommand = cmd;
roomTableAdapter.Adapter.InsertCommand.ExecuteNonQuery();
roomTableAdapter.Adapter.Fill(this.database3DataSet5);
roomTableAdapter.Update(database3DataSet5.room);
dataGridViewX1.Update();
dataGridViewX1.Refresh();
roomTableAdapter.Connection.Close();
答案 0 :(得分:1)
roomTableAdapter.Connection.Open();
string s = string.Format("INSERT INTO `room` ([number], [priceroom]) VALUES (@param1,@param2);");
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(s, roomTableAdapter.Connection);
cmd.Parameters.AddWithValue("@param1", textBoxX4.Text);
cmd.Parameters.AddWithValue("@param2", "4000");
roomTableAdapter.Adapter.InsertCommand = cmd;
roomTableAdapter.Adapter.InsertCommand.ExecuteNonQuery();
roomTableAdapter.Adapter.Fill(this.database3DataSet5);
roomTableAdapter.Update(database3DataSet5.room);
dataGridViewX1.Update();
dataGridViewX1.Refresh();
roomTableAdapter.Connection.Close();
答案 1 :(得分:1)
应该没有"滴答"在Access SQL中。因此:
string s = string.Format("INSERT INTO room ([number], [priceroom]) VALUES (?,?);");