DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   [Databinding] (http://www.daniweb.com/forums/thread117482.html)

Time Indicator Apr 4th, 2008 6:15 pm
[Databinding]
 
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!

Jx_Man Apr 5th, 2008 1:50 am
Re: [Databinding]
 
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?

Time Indicator Apr 7th, 2008 12:04 am
Re: [Databinding]
 
Hi,

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

Mike Serrano Apr 7th, 2008 11:25 am
Re: [Databinding]
 
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.

Time Indicator Apr 7th, 2008 1:53 pm
Re: [Databinding]
 
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

Jx_Man Apr 8th, 2008 2:40 am
Re: [Databinding]
 
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()

Time Indicator Apr 8th, 2008 4:20 pm
Re: [Databinding]
 
Hi,

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


All times are GMT -4. The time now is 7:48 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC