PC Review


Reply
Thread Tools Rate Thread

datatable.row.find method

 
 
Brad
Guest
Posts: n/a
 
      22nd Aug 2004
I need a routine that runs through the current datatable to check for a
duplicate entry using two columns. When I set an array variable to object
and then set each variable's data to find, does the find method search for
var1 or var2, or var1 AND var2? I need it to include any rows that contain
both of these variables.

Here is code that I am using if it might help. If there is another way of
doing this, I am open to suggestions.

Thanks for the information.
Dim foundRow As DataRow

Dim findThese(1) As Object

findThese(0) = dtpEventDate.Value

If cmbShowTrial.SelectedText <> "" Then findThese(1) =
cmbShowTrial.SelectedText Else findThese(1) = ""

foundRow = DsConformation1.Tables(0).Rows.Find(findThese)

If Not (foundRow Is Nothing) Then 'row is found

MsgBox("This entry has already been made")

Exit Sub

End If


 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      22nd Aug 2004
Hi,

The find method will find a data row based on a primary key. The
primary key can be based on more than one column. If you set the primary key
equal to the 2 columns you will get an error if you try to add a duplicate
entry.

http://msdn.microsoft.com/library/de...rykeytopic.asp

http://msdn.microsoft.com/library/de...sFindTopic.asp

Ken
----------------------
"Brad" <(E-Mail Removed)> wrote in message
news:eZo4gh%(E-Mail Removed)...
I need a routine that runs through the current datatable to check for a
duplicate entry using two columns. When I set an array variable to object
and then set each variable's data to find, does the find method search for
var1 or var2, or var1 AND var2? I need it to include any rows that contain
both of these variables.

Here is code that I am using if it might help. If there is another way of
doing this, I am open to suggestions.

Thanks for the information.
Dim foundRow As DataRow

Dim findThese(1) As Object

findThese(0) = dtpEventDate.Value

If cmbShowTrial.SelectedText <> "" Then findThese(1) =
cmbShowTrial.SelectedText Else findThese(1) = ""

foundRow = DsConformation1.Tables(0).Rows.Find(findThese)

If Not (foundRow Is Nothing) Then 'row is found

MsgBox("This entry has already been made")

Exit Sub

End If



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd Aug 2004
Brad,

Bassed on your code I got this idea, why not use a dataview

When you do something the same as now and change every time the rowfilter,
based on your keys, than when the dataview.count is more than one you know
you have a duplicate.

It is just an idea I got when I was looking at your code so not tried.

I hope this helps?

Cor


 
Reply With Quote
 
Brad
Guest
Posts: n/a
 
      22nd Aug 2004
Cor,

Thanks always for your help.

I did decide to use a dataview because as I discovered, the datarow.find
method only works on unique key columns. The criteria that I need to check
for are not unique columns. Using the dataview I search for the first
criteria and if found then I search for the second and if that is found then
I search for the third. If the final criteria is found then I know that
this is a duplicate entry, alerts the user and exits the sub.

Brad


"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Brad,
>
> Bassed on your code I got this idea, why not use a dataview
>
> When you do something the same as now and change every time the rowfilter,
> based on your keys, than when the dataview.count is more than one you know
> you have a duplicate.
>
> It is just an idea I got when I was looking at your code so not tried.
>
> I hope this helps?
>
> Cor
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable.Select vs DataTable.rows.Find vs foreach Dave Microsoft C# .NET 1 17th May 2007 09:06 PM
DataTable.Select Method bug? Adrian Microsoft ADO .NET 3 22nd Jun 2006 07:33 AM
Updating datatable using datatable.rows.find() Lars E Microsoft C# .NET 1 27th Apr 2006 09:28 AM
Retrieving datarows using DataTable.Select method and adding it to new DataTable C.Anand via DotNetMonster.com Microsoft ADO .NET 4 4th Apr 2005 05:21 PM
DataTable, Contains method Millo Microsoft C# .NET 6 9th Jul 2004 06:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 PM.