8 Replies - 941 Views - Last Post: 14 July 2011 - 01:08 PM Rate Topic: -----

#1 zipty05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-July 11

searching within an access database

Posted 14 July 2011 - 08:13 AM

Hey everyone. Needing some help here. I haven't programmed in over a year and I am trying to get this to work. I have a sample database containing 4 columns (First_Name, Last_Name, Emp_Num, and Image). I wanting to type my search criteria in a textbox and search the access database by first and last names. Once the record is found I am wanting to display the name and image for that person. I have already linked my database to my project Any pointers????

Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String
    Dim dr As OleDb.OleDbDataReader





    Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click




        If firstnameTxtBx.Text = " " Then
            Me.firstnameTxtBx.Text = "SELECT First_Name FROM Employee Info WHERE First_Name = firstnametxtbx.text"



            con.Close()

            If Me.resultsTxtBx.Text <> "SELECT * FROM Employee Info WHERE First_Name = firstnametxtbx.text" Then
                Me.resultsTxtBx.Text = "No Record Found"
            End If

        Else
            Me.resultsTxtBx.Text = Me.firstnameTxtBx.Text & " " & Me.lastnameTxtBx.Text

        End If



    

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


      
        dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\Documents and Settings\ldyer\Desktop\IDPhotoProgram\Photos.mdb"

        con.ConnectionString = dbProvider & dbSource

        con.Open()

        sql = "SELECT * FROM Employee Info"
        da = New OleDb.OleDbDataAdapter(sql, con)


    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: searching within an access database

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8365
  • View blog
  • Posts: 31,080
  • Joined: 12-June 08

Re: searching within an access database

Posted 14 July 2011 - 08:43 AM

I am a little confused on what you are doing in your code. The general format is:

  • connection string
  • sql string
  • connection object
  • open connection object
  • sql command created with connection and sql command
  • execute command
  • dataset
  • take results from a read or adapater and shove into the dataset
  • close connection
  • manipulate data in dataset!


Here are some great tutorials to refresh yourself with:

OleDb Basics in VB.Net Rate Topic

A Really Simple Database Create a Database using Access & VB.net Express 2008
Was This Post Helpful? 1
  • +
  • -

#3 zipty05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-July 11

Re: searching within an access database

Posted 14 July 2011 - 11:49 AM

thanks for the links. i am trying to go through the second one right now. im trying to add the button and it is not visible when i hit run.

This post has been edited by zipty05: 14 July 2011 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8365
  • View blog
  • Posts: 31,080
  • Joined: 12-June 08

Re: searching within an access database

Posted 14 July 2011 - 11:52 AM

I don't know what you mean by "the button".
Was This Post Helpful? 0
  • +
  • -

#5 zipty05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-July 11

Re: searching within an access database

Posted 14 July 2011 - 11:56 AM

Sorry.

In the second tutuorial it says add a button to Form1 and the code for that button show be.
Form2.Show()

When I do this no button is visible while the program is running. I didn't touch any of the properties of the button and I even tried to add to the code,
Me.searchBtn.visible = True

But still no button shows.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8365
  • View blog
  • Posts: 31,080
  • Joined: 12-June 08

Re: searching within an access database

Posted 14 July 2011 - 12:15 PM

How did you add the button?
Was This Post Helpful? 0
  • +
  • -

#7 zipty05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-July 11

Re: searching within an access database

Posted 14 July 2011 - 12:16 PM

Dragged it from the toolbox.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8365
  • View blog
  • Posts: 31,080
  • Joined: 12-June 08

Re: searching within an access database

Posted 14 July 2011 - 12:19 PM

Delete it and add a new one.

It sounds like your borked the designer somewhere along the way.
Was This Post Helpful? 0
  • +
  • -

#9 zipty05  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 14-July 11

Re: searching within an access database

Posted 14 July 2011 - 01:08 PM

Okay. I will try that.
Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1