I need help with the syntax for inserting data into specific columns in a table in MS Access, depending on the selected choice from a dropdownlist in asp.net C#. I was planning on passing the name of the column in the table where i'll add the data.
protected void BTNsubmit_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('Order was successfull!');</script>");
if (DDLselectedProduct.SelectedItem.Text == "Tide Wave Burger") AddToDatabase("No_TideWave");
else if (DDLselectedProduct.SelectedItem.Text == "Burger Meaty Delight") AddToDatabase("No_BurgerMeaty");
else if (DDLselectedProduct.SelectedItem.Text == "Darkness Mushroom Burger") AddToDatabase("No_Darkness");
else if (DDLselectedProduct.SelectedItem.Text == "Macaroni Burger") AddToDatabase("No_Macaroni");
else if (DDLselectedProduct.SelectedItem.Text == "Cheesy Burger Delight") AddToDatabase("No_Cheesy");
else if (DDLselectedProduct.SelectedItem.Text == "Amazing Bacon Delight") AddToDatabase("No_Amazing");
else if (DDLselectedProduct.SelectedItem.Text == "Love Me Now Burger") AddToDatabase("No_Love");
else Response.Write("<script>alert('Something went wrong!');</script>");
}
protected void AddToDatabase(string burgerType)
{
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/Burgerlight.mdb"));
connection.Open();
OleDbCommand dbCommand = new OleDbCommand($"insert into Order (Cus_lastname,Cus_firstname,Cus_Tel_no,Cus_address,Cus_zipcode,Cus_province,Cus_city,{burgerType},Type_Trans,Total_Bill) values ('{TXTlname.Text}','{TXTfname.Text}','{TXTtelephone.Text}','{TXTaddress.Text}','{TXTzipcode.Text}','{TXTprovince.Text}','{TXTcity.Text}','{TXTqty.Text}','{DDLdelivery.SelectedValue}','{TXTtotal.Text}');", connection);
dbCommand.ExecuteNonQuery();
connection.Close();
}
I can't seem to find the reason why it keeps getting a syntax error in the Insert Into statement. Can someone help me? Thank you!
question from:
https://stackoverflow.com/questions/65949180/syntax-error-in-insert-into-statement-inserting-data-into-specific-columns 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…