我得到4200 Syntax Error
,當我的MS Access數據庫執行此代碼:語法錯誤INSERT INTO使用OdbcConnection
protected void Button1_Click(object sender, EventArgs e)
{
using (OdbcConnection conn = new OdbcConnection(@"Dsn=ani;dbq=D:\anita\inventory\chemicals.accdb;defaultdir=D:\anita\inventory;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin"))
{
conn.Open();
string CommandText = "INSERT INTO SupplierDetails (ID, Supplier, Company, Address, State, Country, Pincode, PhoneNo, MobileNo, Email, Fax, RawMaterials, Note) VALUES (@ID, @Supplier, @Company, @Address, @State, @Country, @Pincode, @PhoneNo, @MobileNo, @Email, @Fax, @RawMaterials, @Note)";
using (OdbcCommand cmd = new OdbcCommand(CommandText, conn))
{
cmd.Parameters.AddWithValue("@ID", TextBox3.Text);
cmd.Parameters.AddWithValue("@Supplier", TextBox4.Text);
cmd.Parameters.AddWithValue("@Company", TextBox1.Text);
cmd.Parameters.AddWithValue("@Address", TextBox11.Text);
cmd.Parameters.AddWithValue("@State", TextBox2.Text);
cmd.Parameters.AddWithValue("@Country", TextBox5.Text);
cmd.Parameters.AddWithValue("@Pincode", TextBox10.Text);
cmd.Parameters.AddWithValue("@PhoneNo", TextBox6.Text);
cmd.Parameters.AddWithValue("@MobileNo", TextBox7.Text);
cmd.Parameters.AddWithValue("@Email", TextBox8.Text);
cmd.Parameters.AddWithValue("@Fax", TextBox9.Text);
cmd.Parameters.AddWithValue("@RawMaterials", TextBox12.Text);
cmd.Parameters.AddWithValue("@Note", TextBox13.Text);
cmd.ExecuteNonQuery();
}
}
}
你確定你有相關的命名空間嗎? (也請提供更多詳情,歡迎致SO)。 – 2013-03-24 08:53:17
你有相關的命名空間 – anita 2013-03-24 08:56:40
哪一行你會得到錯誤? – 2013-03-24 08:57:29