这总是返回一个错误cmd.ExecuteScalar()
告诉我The parameterized query '(@Name nvarchar(4000))select count(*) from Locations where name=' expects the parameter '@Name', which was not supplied.
我做错了什么?位置是一个字符串。
int count = 0;
using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("select count(*) from Locations where name=@Name", conn);
cmd.Parameters.AddWithValue("@Name",location);
conn.Open();
count = (int)cmd.ExecuteScalar();
conn.Close();
}