Click here to Skip to main content
15,881,866 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI. I am working with MS Access and vb.net . but i am finding it difficult to create a search textbox which will allow me to retrieve a specific record from Ms access database by inputting a value into a search box and the search results displayed into text boxes on the visual basic form. Meanwhile i have already attached my Ms Access database to my vb project Please help... thanks.
Posted
Updated 30-Jan-20 9:08am
Comments
ZurdoDev 6-Dec-12 12:23pm    
We need more info. Where are you stuck?
TugBest 15-Dec-12 7:47am    
i Code this code and it is working perfecting for my results displaying in the text boxes. but my results must come with a picture in a picturebox on the form. I don't how i can get my picture to display in the picture box with the other search results in the textboxes.
i have erors like:- ("Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'")
THIS IS THE CODE BELOW.
NB: the commented code is where am facing problem.

Dim strsql As String = "select FullName,DateofBirth,Emailaddress,Pictures from EntDb where FullName like('" + TextBox11.Text + "%')"
Dim strcon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Avo\Documents\chk.accdb"
Dim odapre As New OleDb.OleDbDataAdapter(strsql, strcon)
Dim datTable As New DataTable
Dim incount As Integer
odapre.Fill(datTable)
For incount = 0 To datTable.Rows.Count - 1
FullNameTextBox1.Text = datTable.Rows(incount)("Fullname").ToString
DateofBirthDateTimePicker.Text = datTable.Rows(incount)("DateofBirth").ToString
EmailaddressTextBox.Text = datTable.Rows(incount)("Emailaddress").ToString
' PicturesPictureBox1. = datTable.Rows(incount)("Pictures")
next
end sub
ridoy 6-Dec-12 13:37pm    
need some clear info here..do you want autocompleteness for you textbox(as like google search textbox) where the matching values with input would be shown form your database?
TugBest 15-Dec-12 10:12am    
i want matching values with input to be shown from my database with the matching picture in a picturebox. Everything works when i comment out the picture code.
so i need a little help for the picture to display in a picturebox.

i have erors like:- ("Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'")
THIS IS MA CODE:
Dim strsql As String = "select FullName,DateofBirth,Emailaddress,Pictures from EntDb where FullName like('" + TextBox11.Text + "%')" Dim strcon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Avo\Documents\chk.accdb" Dim odapre As New OleDb.OleDbDataAdapter(strsql, strcon) Dim datTable As New DataTable Dim incount As Integer odapre.Fill(datTable)

For incount = 0 To datTable.Rows.Count - 1

FullNameTextBox1.Text = datTable.Rows(incount)("Fullname").ToString

DateofBirthDateTimePicker.Text = datTable.Rows(incount("DateofBirth").ToString
EmailaddressTextBox.Text = datTable.Rows(incount)("Emailaddress").ToString
' PicturesPictureBox1.image = datTable.Rows(incount)("Pictures")
next
end sub

1 solution

Don *NOT* use a text box to display your results.

Here is some reading for you, after which you should be able to bang this out in minutes.

Parameterized Queries[^] - Great Post

Use that to get a data table and read this
DataGridView[^]

Then look at this to run your queries in the background to not stop your thread
BackgroundWorker[^]

Then tie into your textbox OnChange (or KeyUp depending on your requirements) to run the query in the background and populate the DataGridView.
 
Share this answer
 
Comments
TugBest 15-Dec-12 7:54am    
thanks very much

i Code this code and it is working perfecting for my results displaying in the text boxes. but my results must come with a picture in a picturebox on the form. I don't how i can get my picture to display in the picture box with the other search results in the textboxes.

THIS IS THE CODE BELOW.
NB: the commented code is where am facing problem.

Dim strsql As String = "select FullName,DateofBirth,Emailaddressfrom Entdb where FullName like('" + TextBox11.Text + "%')"
Dim strcon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Avo\Documents\chk.accdb"
Dim odapre As New OleDb.OleDbDataAdapter(strsql, strcon)
Dim datTable As New DataTable
Dim incount As Integer
odapre.Fill(datTable)
For incount = 0 To datTable.Rows.Count - 1
FullNameTextBox1.Text = datTable.Rows(incount)("Fullname").ToString
DateofBirthDateTimePicker.Text = datTable.Rows(incount)("DateofBirth").ToString
EmailaddressTextBox.Text = datTable.Rows(incount)("Emailaddress").ToString
' PicturesPictureBox1. = datTable.Rows(incount)("Pictures")
next
end sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900