ASP.NET C#错误必须声明标量变量

时间:2017-08-06 07:49:38

标签: c# asp.net

我已经宣布了,为什么我会收到错误?

conn.Open();
String strCount = "Select SUM(freight) AS TOTAL from Orders where EmployeeID = @employee AND Year(OrderDate)= @Oyear";
SqlCommand cmdCount = new SqlCommand(strCount, conn);

cmdSelect.Parameters.AddWithValue("@employee", DropDownList1.SelectedValue.ToString());
cmdSelect.Parameters.AddWithValue("@Oyear", RadioButtonList1.SelectedValue.ToString());

double intCount = (double)cmdCount.ExecuteScalar();
Label1.Text = intCount.ToString();
conn.Close();

1 个答案:

答案 0 :(得分:1)

您正在将参数添加到错误的命令中。

更改您添加参数的命令名称,它将起作用:

cmdCount.Parameters.AddWithValue("@employee", DropDownList1.SelectedValue.ToString());
cmdCount.Parameters.AddWithValue("@Oyear", RadioButtonList1.SelectedValue.ToString());