Hi all,
Here i am using checkbox list control and a button.In button click i
wrote below code to insert values into a table in database.I write this
code in loop because of I am using check box list control....
when i run my webform user can select single check box or multiple
check boxes then when button click i want to insert those checked
values into my table which has only one column
But when inserting from second record its showing below error....
The
variable name '@counselor_name' has already been declared. Variable
names must be unique within a query batch or stored procedure.
Here below is my code....
string st = "";
foreach (ListItem li in Chkcounselor.Items)
{
if (li.Selected)
{
st = li.Text.ToString();
SqlParameter counselorname = new SqlParameter("@counselor_name", SqlDbType.VarChar, 50);
counselorname.Value = st;
cmd.Parameters.Add(counselorname);
cmd.ExecuteNonQuery();
}
}
Please help me out....
thank you.
Loading
satheesh babuPosted Nov 25, 2008, 3:48 AM
Its working......
Blocked AccountPosted Nov 25, 2008, 3:40 AM
Hi,
Also create the new SqlCommand object for each list item like that.
SqlCommand cmd = new SqlCommand(query, connection)
Before the line cmd.Parameters.Add(counselorname);
I think it will resolve your problem.