I am creating a simple desktop sample for T-SQL but for some reason it throws an exception.
Exception appears at int j = cmd.ExecuteNonQuery();
DateTime d = DateTime.Now;
String Id = textBox4.Text;
String date = d.ToString();
String quantity = textBox2.Text;
String connectionstring = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Junaid Computers\source\repos\WindowsFormsApp3\Softech.mdf;Integrated Security = True";
SqlConnection con = new SqlConnection(connectionstring);
String query = "INSERT INTO order (CustomerId,OrderDate,OrderQuantity) VALUES('" Id "','" date "','" quantity "')";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int j = cmd.ExecuteNonQuery();
if (j > 0)
{
MessageBox.Show("Data Inserted:");
}
else if (j == 0)
{
MessageBox.Show("SOrry! No Insertion:");
}
CodePudding user response:
Try INSERT INTO \"order\".
The word "order" is a reserved keyword.
This worked for me.