System.Data.SqlClient.SqlException:'3附近的语法不正确。'

时间:2019-08-16 04:51:25

标签: c# sql-server

这是我的代码,因此我无法执行任何操作。我不知道这是怎么回事

private void Button1_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(@"Data Source=   (LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\alswy\Documents\Farm Stock Management.mdf;Integrated Security=True;Connect Timeout=30");

    //Logic Input
    con.Open();
    SqlCommand cmd = new SqlCommand(@"INSERT INTO [FarmStockt].[dbo].[Products]([CropID],[CropName],[CropStatus],[Fertilizer],[SowingTime],[SowingMethod],[StorageType],
[MinTemp],[MaxTemp],[Vehicles],[Containers],[Quantity]) VALUES ('" + txtCropID.Text +"','"+ txtCropName.Text + "','" + comboStatus.SelectedIndex + "','" + comboFertilzer.Text + "','" + txtSowing.Text + "','"
+ txtMethod.Text +"','" +txtStorage.Text +"','" + comboTemp.Text + "','" + comboBox2.Text + "','" + comboVehicles.Text + "','" + comboBox1.Text + "','" + comboQuantity.Text +"'",con);
    cmd.ExecuteNonQuery();
    con.Close();
}

0 个答案:

没有答案