473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

datatable.row.find method

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
Nov 21 '05 #1
3 26608
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" <al*******@sbcglobal.net> wrote in message
news:eZ****************@TK2MSFTNGP11.phx.gbl...
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

Nov 21 '05 #2
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
Nov 21 '05 #3
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" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: doug | last post by:
I would like to do a select distinct on a fieldname in a dataset. Is this possible using the DataTable.Select Method? If so do you have an example? I can use the method to do things like...
5
by: harry | last post by:
Hi, Can the DataTable.Select Method use 'Distinct' to remove duplicate rows? If so how? I tried, however code triggered error 'no colmn 'Distinct' found'. Thanks Harry
1
by: mirandacascade | last post by:
I do not understand how to use the find() method in ElementTree. The file 'sample.xml' is: <?xml version="1.0"?> <SampleRoot> <Header> <Product>FindMystery</Product> </Header>...
6
by: Millo | last post by:
Hi I'm trying to call the method Contains in a loop: out of the loop I set the primary key of the dataTable. The method returns true one time at a certani value, but then, when the loop steps...
1
by: Joe Smith | last post by:
Hello, Can we do SQL style SELECT queries in the DataTable.Select Method. e.g Filter String Expression = id < 5 AND (age <20 OR age >50) My goal is to be able to do advanced queries on a...
3
by: emailtonitin | last post by:
Hi, I am having a problem with the default sorting mechanism employed by the datatable.select method - I have a datatable having rows (simplified for clarity) - name ----- c a
0
by: njuneardave | last post by:
This line of code will make the Find method search for a search key in a given range if you search from top to bottom: m_form.richTextBox1.Find(searchKey, searchDownAreaStart, searchDownAreaEnd,...
2
by: cameljs18 | last post by:
I have a datatable into which i insert data then display the data in a datagridview.When i want to clear the table and place completely new data in the table, the table still retains the column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.