problem records insertion through asp.net
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.