向数据库写入数据出错,“System.Data.OleDb.OleDbException”类型的未经处理的异常在 System.Data.dll 中发生 其他信息: 查询值的数目与目标字段中的数目不同。

向数据库写入数据出错,“System.Data.OleDb.OleDbException”类型的未经处理的异常在 System.Data.dll 中发生   其他信息: 查询值的数目与目标字段中的数目不同。

问题描述:

public: System::Void OpenAccess()

{
String^ oleDBString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Office2019\MyProject\sensor.accdb;";
OleDbConnection^ os = gcnew OleDbConnection(oleDBString);
String^ sql = "select* from Sensor1";
DataSet^ ds = gcnew DataSet();
OleDbDataAdapter^ oleDbDataAdapter = gcnew OleDbDataAdapter(sql, os);
oleDbDataAdapter->Fill(ds);
dataGridView1->DataSource = ds->Tables[0]->DefaultView;
os->Close();
}
private: System::Void button9_Click(System::Object^ sender, System::EventArgs^ e) {
String^ text1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Office2019\MyProject\sensor.accdb;";
String^ text2 = "Insert Into Sensor1(Temperature,Humidity)Values(";
text2 += textBox4->Text + ",";
text2 += textBox6->Text + ")";
OleDbConnection^ conn = gcnew OleDbConnection(text1);
conn->Open();
OleDbCommand^ da = gcnew OleDbCommand();
da->CommandText = text2;
da->Connection = conn;
da->ExecuteNonQuery(); // 出错行!!!!
textBox4->Text = "";
textBox6->Text = "";
conn->Close();
}

String^ text2 = "Insert Into Sensor1(Temperature,Humidity)Values(";
text2 += textBox4->Text + ",";
text2 += textBox6->Text + ")";
你Temperature,Humidity)Values中间的逗号是全角的