Results 1 to 4 of 4

Thread: trying to code search button

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    2

    trying to code search button

    Hey Guys and gals

    I'm trying to code a search button to pull back info from access database and populate text and combo boxes as wellas a couple date time pickers. I can't seem to get the program to bring back any results. this is the code i have (and please tell me if there is an easier way to do what i'm trying to do.)


    Code:
    connection.ConnectionString = "provider=microsoft.jet.oledb.4.0;Data source=q:\data\isim.mdb"
    
            connection.Open()
            searchtime = "SELECT * FROM isimtable WHERE serial = '*" & tbSerial.Text & "*'"
            adapter = New OleDb.OleDbDataAdapter(searchtime, connection)
            adapter.Fill(searchresults, "Search")
     
                cbModel.Text = searchresults.Tables("search").Rows(0).Item(1)
                tbSerial.Text = searchresults.Tables("search").Rows(0).Item(2)
                tbAsset.Text = searchresults.Tables("search").Rows(0).Item(3)
                rtbHistory.Text = searchresults.Tables("search").Rows(0).Item(4)
                rtbNotes.Text = searchresults.Tables("search").Rows(0).Item(5)
                tbUser.Text = searchresults.Tables("search").Rows(0).Item(6)
                cbLocation.Text = searchresults.Tables("search").Rows(0).Item(7)
                cbSchedule.Text = searchresults.Tables("search").Rows(0).Item(8)
                dtpDateSent.Text = searchresults.Tables("search").Rows(0).Item(9)
                dtpDateRec.Text = searchresults.Tables("search").Rows(0).Item(10)
                tbPrevUser.Text = searchresults.Tables("search").Rows(0).Item(11)
    this is run from a cmd_click on btnGO when i run it, i get IndexOutOfRangeException was unhandled
    There is no row at position 0, so what i gather is the dataset is not filling with any info. Problem is i can't figure out why. I know what i enter when i search is valid in the database. Please help. Any suggestions would be great.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: trying to code search button

    What are the stars in the serial value for? You'd only use them with a LIKE operator, not '='.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Posts
    2

    Re: trying to code search button

    thank you sooooo much jmchil. You don't know how long i've been looking at this. Works great. Thanks again.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: trying to code search button

    You should not assume that there will be a row unless you can absolutely guarantee that a record with a matching serial will be present. What if the user enters a value that's not in the table? You'll be back to the same error.

    Also, unless you intend to edit and save that data you should use a DataReader rather than a DataAdapter to retrieve the data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width