Reputation: 3
I declared already so why do I get an error?
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();
Upvotes: 0
Views: 413
Reputation: 66388
You are adding the parameters to the wrong command.
Change the command name you add the parameters to, and it will work:
cmdCount.Parameters.AddWithValue("@employee", DropDownList1.SelectedValue.ToString());
cmdCount.Parameters.AddWithValue("@Oyear", RadioButtonList1.SelectedValue.ToString());
Upvotes: 1