Hi,

I need help with importing database into form. The problem that I am having is, when a user inputs their firstname into textbox1, it should search for their name in the database (MS Access) , if found, it should populate the information into each textbox such as lastname, address and etc.., I know that you have to use datareader to do that and databinding to add the information to the textboxes, but how do I do the search and then populate the information. I am using access database. Can you please help me on this?

Thanks in advance!

Recommended Answers

All 6 Replies

you can do generally searching??
if u can, its a same technique.
put you search procedure in text change event. so when user input data on textbox it will searching others data.
but why u using first name as searching key??
how about if you have 2 same frist name in your database??why you didn't used their id?

Hi,

Okay, If I were to search the ID, how do I go about that. Can you provide me a sample code? Thanks

I the dataset designer create a TableAdapter with the following DML:
SELECT * FROM Table WHERE Name LIKE '%?%'

Add the DataSet and the TableAdapter to the form and bind the controls (I recomend a DataGrid to see all the records that math the query).
In the TextBox1 open the Text Change Event and write the following code:

TABLEADAPTER_NAME.FILL(DataSet.TableName, TextBox1.Text.Trimm)

Sorry for my bad english.

Hi,

Here is my code to do a Select function. However, how do I modify this code to do a search function. In other words, the user has to input the customerID onto a textbox 1, which then searches for the information in the database and populate it to all other textboxes. Right now, my code has data populated into a datagrid. Can anyone help? Thanks in advance!

Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\testing\nwind.mdb;")

Dim myComamand As New OleDbCommand
Dim myDataReader As OleDbDataReader
Dim myDataTable As New DataTable

Try
myConnection.Open()
myComamand.CommandType = CommandType.Text
myComamand.Connection = myConnection
myComamand.CommandText = "Select CustomerID From Customers"

myDataReader = myComamand.ExecuteReader()

myDataTable.Load(myDataReader)

DataGridView1.DataSource = myDataTable

Catch ex As Exception
MsgBox(ex.Message)
Finally
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
End Try

do you want to populate data in datagrid or other control (label or textbox).
i looks in your code you able to populate in datagrid. so try this to populate in textbox or label.
add this code on your code :

If myReader.HasRows Then	
	While myReader.Read()
		txtFirstName.text= myReader.Item("FirstName") 
	End While
End If
myReader.Close()
commented: Got it :) +1

Hi,

Thanks for all your help! It worked....:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.