System.Data.OleDb.OleDbConnection bes = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\JAMES DEAN\Documents\aha.mdb;User Id=admin; Password=;;");
System.Data.DataTable pc = new System.Data.DataTable();
System.Data.OleDb.OleDbDataAdapter save = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Info (Quantity, Unit, Account, Description , Amount, Total Amount, [Date]) VALUES '"+ textBox1.Text +"','" +textBox2.Text +
"','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5 + "','" + textBox6.Text+ "','" + dateTimePicker1.Value.ToString("MM/dd/yyyy") + "','" ,bes);
save.Fill(pc);
dataGridView1.DataSource = pc;
谢谢:D
System.Data.OleDb.OleDbCommand save = new System.Data.OleDb.OleDbCommand(
"Insert into Info (Quantity, Unit, Account, Description , Amount, Total Amount, Account Title, [Date]) VALUES '"
+ textBox1.Text +"','"
+textBox2.Text +"','"
+ textBox3.Text + "','"
+ textBox4.Text + "','"
+ textBox5 + "','"
+ textBox6.Text+ "','"
+ comboBox1.Text+"','"
+ dateTimePicker1.Value.ToString("MM/dd/yyyy") + "','" ,bes);
save.ExecuteNonQuery();
bes.Close();
现在这是我的代码,我仍然得到错误TT
答案 0 :(得分:0)
您正在混合两个查询Select
和Insert
选择强>
SELECT Quantity, Unit, Account, Description , Amount, Total Amount, [Date] FROM Info
插入强>
Insert into Info (Quantity, Unit, Account, Description , Amount, Total Amount, [Date]) VALUES ...
另外
1.列之间不能有空格。
2.请使用参数化查询来防止SQL注入。