Windows Develop Bookmark and Share   
 index > Windows Forms General > How to search a table in a dataSet for value?
 

How to search a table in a dataSet for value?

Hi,

i have a dataset (ds), with a table (T1).

T1 has a number of columns.

2 of which are Id and Code.

I get passed a Code.

How do i search T1 Code column and return the corresponding Id to a variable?

similar to a sql search with a where clause.

(Select T1.ID from T1 where T1.Code = 'code')

Thanks.

allison_h  Wednesday, May 16, 2007 11:08 AM

Hi,

You can use the Select() method of the Table class to select rows from the table that match a certain criteria, it's very similar to a select statement. The method returns an array of DataRows that you can iterate over. Just like a select statement you need to use [ ] around column names and ' ' around strings. Here's a basic example...

Dim rows() as DataRow

rows = myTable.Select("[Code] = '" & myCode & "'")

For each row as DataRow in rows

Derek Smyth  Wednesday, May 16, 2007 11:20 AM

Hi,

You can use the Select() method of the Table class to select rows from the table that match a certain criteria, it's very similar to a select statement. The method returns an array of DataRows that you can iterate over. Just like a select statement you need to use [ ] around column names and ' ' around strings. Here's a basic example...

Dim rows() as DataRow

rows = myTable.Select("[Code] = '" & myCode & "'")

For each row as DataRow in rows

Derek Smyth  Wednesday, May 16, 2007 11:20 AM

You can use google to search for other answers

Custom Search

More Threads

• CellEndEdit Too Late. CellValueChanged Too Early.
• How can I Simulate a Mouse wheel down by MouseInput
• Customizing AxWebBrowser content while printing
• Do something after ShowDialog
• right click event ??
• Ctrl-Ins Shift-Ins
• Dont know where to keep files to be accesed by app(including mdb, txt, ini files)
• Why ToolStripItem inherits from Component instead of Control?
• Running a nested message loop
• Minimizing/Restoring owner form when child dialog was minimized/restored