我在我的代码
上收到此错误消息system.data.sqlclient.sqlexception&nbspchar'
附近的语法不正确必须声明标量变量@Flag
这是我到目前为止的代码:
try
{
if (dbConn.State == ConnectionState.Closed)
{
dbConn.Open();
}
dbCmd = new SqlCommand("INSERT INTO Shop(ShopID,ShopName,Location,Size,CostPerMeter,[TenantID(FK)],Flag)" +
"VALUES(@ShopID,@ShopName,@Location,@Size,@CostPerMeter,@[TenantID(FK)],@Flag);", dbConn);
dbCmd.Parameters.AddWithValue("@ShopID", txtPrimary.Text);
dbCmd.Parameters.AddWithValue("@ShopName", txtShopName.Text);
dbCmd.Parameters.AddWithValue("@Location", txtLoc.Text);
dbCmd.Parameters.AddWithValue("@Size", txtSize.Text);
dbCmd.Parameters.AddWithValue("@CostPerMeter", txtCPM.Text);
dbCmd.Parameters.AddWithValue("@[TenantID(FK)]", txtTenID.Text);
dbCmd.ExecuteNonQuery();
ds.Tables["Shop"].Rows.Add(new object[] { txtPrimary.Text, txtShopName.Text, txtLoc.Text, txtSize.Text, txtCPM.Text, txtTenID.Text, });
txtPrimary.Clear();
txtShopName.Clear();
txtLoc.Clear();
txtSize.Clear();
txtCPM.Clear();
txtTenID.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
答案 0 :(得分:3)
您在查询中引用@Flag
,但绝不给它相应的参数值。只需为@Flag
添加参数值:
dbCmd.Parameters.AddWithValue("@Flag", true); // set however appropriate