当我尝试从Visual stutio使用C#中的Access数据库中插入数据我不断收到此错误在INSERT INTO语句中的System.Data.OleDb.OleDbException:语法错误。 “使用C#从Visual Studio插入数据从Visual Studio的Access数据库
保护无效Button1_Click1(对象发件人,EventArgs的) {
Guid newGUID = Guid.NewGuid();
OleDbConnection conn = new OleDbConnection(" Provider = Microsoft.ACE.OLEDB.12.0;" + "Data Source = " + Server.MapPath("App_Data/Group.accdb"));
OleDbCommand command = new OleDbCommand ("INSERT INTO [User] ([Userid], [UserName], [Password], [Email], [Country], [CartID], [Address]) VALUES (@Uname,@password,@email,@country,@address,@userid,@cartID)", conn);
conn.Open();
command.Parameters.AddWithValue("@userid", Convert.ToString(newGUID));
command.Parameters.AddWithValue("@Uname", username.Text);
command.Parameters.AddWithValue("@password", username.Text);
command.Parameters.AddWithValue("@email", email.Text);
command.Parameters.AddWithValue("@country", DropDownList1.SelectedItem.ToString());
command.Parameters.AddWithValue("@cartID", Convert.ToString(newGUID));
command.Parameters.AddWithValue("@address", address.Text);
command.ExecuteNonQuery();
conn.Close();
Response.Redirect("Login.aspx");
Response.Write("Registration is successful");
}
它仍然给我的错误 –
一切在你的代码看起来很好 - 我认为它会起作用,这导致我相信它可能像字段名称中的拼写错误一样简单。你可以添加你的桌面布局的屏幕截图吗? – Hambone