untyped datatable

G

Guest

hey all,
if i have an untyped datatable in my code how can i make it where when i
reference the datatable variable i can say dt.FindByFieldKeyID(value as
integer)?

thanks,
rodchar
 
T

Teemu Keiski

Hi,

DataTable.Rows.Find method is probably the closest, if you mean searching
with primary key value?
 
G

Guest

how do i create or designate the primary key field in my untyped datatable?

DataTable dt;
dt=da.GetDataTable()
dt.Find ???
 
T

Teemu Keiski

You need to first specify the PK in the datatable.

'This way to say that first column is the PK
dt.PrimaryKey = New DataColumn() {dt.Columns(0)}

'This way to say that more than one columns together are the PK
dt.PrimaryKey = New DataColumn() {dt.Columns(0), dt.Columns(1)}

'You can also use colun name
dt.PrimaryKey = New DataColumn() {dt.Columns("IDOne"),
dt.Columns("IDTwo")}

Then you can look for a specific row with a PK value

Dim row As DataRow = dt.Rows.Find(15)

If Not row Is Nothing Then
Dim thevalue As String = row("OtherColumn").ToString()
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top