[英]Scalar variable not declared
protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
{
var connectionString = (ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
var updateCmd = "UPDATE [CarTab] SET Rent= 1 WHERE ([Model] = @Model)";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(updateCmd, connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
}
Error : Must declare scalar variable for @Model. 错误:必须为@Model声明标量变量。 What should I remove/add there? 我该删除/添加什么? Can't figure it out. 无法弄清楚。 Thanks in advance. 提前致谢。
You can try with 你可以试试
command.Parameters.AddWithValue("@Model", value);
You complete code 你完成代码
protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
{
var connectionString = (ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
var updateCmd = "UPDATE [CarTab] SET Rent= 1 WHERE ([Model] = @Model)";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
using(var command = new SqlCommand(updateCmd, connection))
{
command.Parameters.AddWithValue("@Model", value); //Replace with your value
command.Connection.Open();
command.ExecuteNonQuery();
}
}
}
You must add the parameter @Model
, like: 您必须添加参数@Model
,如:
updateCmd.Parameters.Add("@Model", SqlDbType.SomeType);
updateCmd.Parameters["@Model"].Value = something;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.