5 Replies - 1787 Views - Last Post: 12 February 2012 - 07:06 PM Rate Topic: -----

#1 hjarrell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-January 12

How to search an access database table to see if a value exists.

Posted 09 February 2012 - 01:03 PM

Hi i am trying to search a table in an access database to see if the value of a text box exists in it. I have this so far:

Dim myConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.LocalUserAppDataPath & "\Database" & "\Student Aid Database.mdb")

            myConnection.Open()

to open the connection but i am stuck now.

Is This A Good Question/Topic? 0
  • +

Replies To: How to search an access database table to see if a value exists.

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9277
  • View blog
  • Posts: 34,787
  • Joined: 12-June 08

Re: How to search an access database table to see if a value exists.

Posted 09 February 2012 - 01:08 PM

Now you create a dataset to hold your results, and a sql data adapter giving it a sql statement and your connection string.. and then you fill your dataset from the adapter!
Was This Post Helpful? 0
  • +
  • -

#3 hjarrell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-January 12

Re: How to search an access database table to see if a value exists.

Posted 12 February 2012 - 10:49 AM

I got that part but will you please help me with the sql command i'm lost.
Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: How to search an access database table to see if a value exists.

Posted 12 February 2012 - 11:05 AM

Dim sqlstr As String

sqlstr = "SELECT * FROM tableName WHERE columnName = '" & Trim(Textbox.Text) & "'

Dim command As New SqlCommand(sqlstr, conString)

Was This Post Helpful? 0
  • +
  • -

#5 hjarrell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-January 12

Re: How to search an access database table to see if a value exists.

Posted 12 February 2012 - 06:54 PM

View PostnK0de, on 12 February 2012 - 11:05 AM, said:

Dim sqlstr As String

sqlstr = "SELECT * FROM tableName WHERE columnName = '" & Trim(Textbox.Text) & "'

Dim command As New SqlCommand(sqlstr, conString)


Thanks but how would i apply the if for the:
command.ExecuteReader()


Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: How to search an access database table to see if a value exists.

Posted 12 February 2012 - 07:06 PM

If you only need to check if the data exists, I will advice using DataReader, it is easy to use for read only and it has functionality to check if returned has rows or not.
Check an example here, you just assign the returned value of ExecuteReader() to your data reader and then use the data reader for the rest of the issue:
http://msdn.microsof...v=vs.71%29.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1