SQL, Visual Studio 2005, C #

Oct 20 2006 2:19 AM
I am facing problem with the code to delete single/multiple row(s) on button click from a datagrid.

The datagrid consists of selectall checkbox. Once a user clicks on this checkbox, all the checkboxes besides each row on that page are checked. Else he can check any one or two rows in the grid to delete just a particular row.

Also, topic id is primary key whose datatype is int.
 
The code is as follows:

protected void btndelete_Click(object sender, EventArgs e)

{

foreach (DataGridItem dgi in MyDataGrid.Items)

{

CheckBox checkall;

checkall = (CheckBox)dgi.FindControl("chkselect");

string topicid = MyDataGrid.DataKeys[dgi.ItemIndex].ToString();

if (checkall.Checked==true)

{

string delrecord="delete from Admin_Add_Newsletter_Topic where Topic_Id= topicid";

SqlConnection con=new SqlConnection(ConnectionString);

SqlCommand cmd=new SqlCommand(delrecord, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

}

}

}


 But I receive this error:

Invalid column name 'topicid'.

Please help me


Answers (1)