Deleting multiple records(rows) from tables using checkboxes

I have a datagrid with checkboxes..
When a user clicks one check box and clicks the delete button it deletes
that ROw.
There another situation when a user clicks multiple rows so i had to loop
throug the rows like so:-
foreach (DataGridItem i in DataGrid1.Items)
{
CheckBox deleteChkBxItem = (CheckBox) i.FindControl ("DeleteRow");
if (deleteChkBxItem.Checked)
{
BxsChkd = true;
// Concatenate DataGrid item with comma for SQL Delete
dgIDs += ((Label) i.FindControl ("postID")).Text.ToString() + ",";
}
}
The postid is integer and it has to be Concatenate with comma to delete
multiple rows..
If i do deleteSQL = "DELETE from prodcuts WHERE postID IN (" +
dgIDs.Substring (0, dgIDs.LastIndexOf (",")) + ")";
using inline code it works
But if i move it to a stored procedure and select multiple rows to delete it
gives me error
Error converting data type nvarchar to int.!!!
And i guess converting string to integer would hard since it has a comma in
it.
I tried
string p = dgIDs.Substring (0, dgIDs.LastIndexOf (","));
h = Int32.Parse(p);//No sense here i know
Any way around this

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!