Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
SQL, Visual Studio 2005, C #
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Sandhya Bhosale
17y
2k
1
Reply
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
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Error Upon Restoring Transaction Log
BLBO