Deleting A Row from a DataTable based on ID column

rito1 used Ask the Experts™
Hi All,

I have a DataTable stored within a Session variable like so..

        DataTable myDt = new DataTable();
        myDt = createTempDatesTable();
        Session["TempDataTable"] = myDt;

The DataTable has a column called 'ID' which stored string values.

Please could anyone show me how to delete a row from my DataTable based on a value within the ID column.?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

If ID column is the primary column, then you can use like:

DataRow foundRow = myDt.Rows.Find("idValue");
Top Expert 2010

D columns in not primary key, then you can use like:

string id = "123";
DataRow[] foundRows = myDt.Select(string.Format("ID Like '{0}%'", id));
foreach(DataRow row in foundRows) // if there is only one for the id, then foundRows will have one row only


Excellent, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial