|
-
Jul 20th, 2007, 09:05 AM
#1
Thread Starter
New Member
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.
-
Jul 20th, 2007, 09:17 AM
#2
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 '='.
-
Jul 20th, 2007, 09:26 AM
#3
Thread Starter
New Member
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.
-
Jul 20th, 2007, 06:05 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|