【发布时间】:2017-08-06 07:49:38
【问题描述】:
我已经声明了,为什么会报错?
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();
【问题讨论】:
-
您的命令对象的名称是什么?
cmdCount或cmdSelect? -
您应该查看Can we stop using AddWithValue() already? 并停止使用
.AddWithValue()- 它可能会导致意想不到和令人惊讶的结果... -
没有用.AddWithValue()我们可以用什么方法解决?
-
在那篇文章中清楚地解释了 - 请阅读!