これは常にエラーを返し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();
}