我已经宣布了,为什么我会收到错误?
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();
答案 0 :(得分:1)
您正在将参数添加到错误的命令中。
更改您添加参数的命令名称,它将起作用:
cmdCount.Parameters.AddWithValue("@employee", DropDownList1.SelectedValue.ToString());
cmdCount.Parameters.AddWithValue("@Oyear", RadioButtonList1.SelectedValue.ToString());