Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ds.Tables[0].Select() represents

Tags:

c#

asp.net

What dr gets here.

DataRow[] dr = objds.Tables[0].Select("ProcessName = '" + tnProcName.Text + "'");

I am getting dr{System.Data.DataRow[4]} and not the line individually.

In dr now consists of list of rows.How can i compare the column present in data row.

like image 352
Ravi Kiran Ayinampudi Avatar asked Nov 30 '25 03:11

Ravi Kiran Ayinampudi


1 Answers

It returns an array of DataRow that match the selection criteria expressed by the first parameter of the Select method

DataRow[] dr = objds.Tables[0].Select("ProcessName = '" + tnProcName.Text + "'");
foreach(DataRow r in dr)
{
   string procName = r["ProcessName"].ToString();
   treeView1.Nodes.Add(procName);

}

Select has four overloads to fine tune the results

DataTable.Select(); // return all (same as dataTable.Rows)
DataTable.Select(filter); //The above one
DataTable.Select(filter, sort) //Filtered and/or sorted
DataTable.Select(filter, sort, rowstate) // Filtered and/or sorted and/or in a particular state

Here the MSDN docs

Probably it is not your case, but keep in mind that if the expression parameter has a single quote then you need to double it to avoid a syntax error when the expression is evaluated

DataRow[] dr = objds.Tables[0].Select("ProcessName = '" + 
               tnProcName.Text.Replace("'", "''") + "'");
like image 53
Steve Avatar answered Dec 02 '25 17:12

Steve