Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to search for a value in the primary key column in a datatable to see if there is a match. If there is a match, I will display a message that this is a duplicate value.

 

How do I search a value in the primary key column, or are there different ways of accomplishing this?

 

Any help is appreciated.

Posted
Would a normal select of the form

SELECT <PK Column Name> FROM <Table Name> WHERE
<PK Column Name> = <value to search for>

not do the trick? Or do you want to actually list the duplicates?

 

 

Thank you for your response. I am working with the Datatable object which is part of a Dataset object. The Datatable object is created in the code. I programmatically add new data to the Datatable object. What I try to do is to verify that the new data to be added to the Datatable does not already exist in the Datatable. If you have any suggestion, I'll appreciate it.

 

Thanks.

Posted
Will this work?

 

Dim r as DataRow = myTable.Rows.Find(ValueToFind)

If r Is Nothing Then
   'The Value was NOT found
Else
   'The value was found
End If

 

 

That works out great!! Thank you so much wayneph. I appreciate it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...