By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,595 Members | 3,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,595 IT Pros & Developers. It's quick & easy.

syntax to compare data from text field, when adding a record, to a field in a table for duplicates

P: n/a
What will be the syntax if I want to compare whether the phone number I
am entering when adding a record already exists in database. The phone
field in that table is set to primary key.

We are using binding source in this application.

Nov 18 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Try something like this.

Load dataset and define primary key
Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection

strConn = "Server = .;Database = NorthWind; Integrated Security =
SSPI;"
conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * from Products", conn)
da.Fill(ds, "Products")
ds.Tables("Products").PrimaryKey = New DataColumn()
{ds.Tables("Products").Columns("ProductID")}

I would try to find the new key. If there is no return value it is ok to
add that key. Here is a simple function to check if it is ok to add
Private Function OkToAdd(ByVal strNewValue As String) As Boolean
Dim dr As DataRow = ds.Tables("Products").Rows.Find(strNewValue)
Return dr Is Nothing
End Function

Ken
-----------------------
"amanda" <am**********@yahoo.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
What will be the syntax if I want to compare whether the phone number I
am entering when adding a record already exists in database. The phone
field in that table is set to primary key.

We are using binding source in this application.

Nov 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.