How to query Access from VB.net and Display information in a text box
Posted on 2006-04-21
Hello how is everyone doing today?.
As for me I'm doing pretty good so far and trying to understand VB.net more each day.
Anyhow What I want to do is query a small access DB file that I have and then display the information within
a text box so then afterwards the user can just edit the text box and submit the new information.
So far I'm having trouble passing the data to the textbox, I tried putting the textbox name and that didnt work so
I know there is something wrong that I'm doing.
So i try to keep things simple 2 text boxes only for demonstration purposes lol
Here is a small sample code
Dim connString As String = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\db2.mdb;"
Dim myConnection As OleDbConnection = New OleDbConnection ' Stores a connection
Dim insertCmd As OleDbCommand = New OleDbCommand 'Stores object of OLEDB Command
myConnection.ConnectionString = connString
'Now to create a search statement
.Connection = myConnection
.CommandText = " Select User_ID,FName From [Names] " & _
" Where User_ID=@User_ID"
.CommandType = CommandType.Text
.Parameters.Add(New OleDbParameter("@User_ID", OleDbType.Char, 10))
.Parameters.Add(New OleDbParameter("@FName", OleDbType.Char, 25))
.Parameters("@User_ID").Value = txtUser.Text *****////Here is the problem /////
.Parameters("@FName").Value = txtFname.Text ******/// and here too ////
As you can see in the ////.Parameter("@USer_ID") I want to pass the information to a text box///
I know im definetly doing something wrong because I know I use example ////.Parameter("@User_ID").Value = Uservariable to compare the data to what
the user is inserting.
This time though I just want to know how to display the information that I have from the database to a text box...In other words transfer it to the text box
and then have another button to submit the new data :)
Also another question ...how in the world do you refresh a dataGrid?....I notice when I do a deletion the datagrid still has the data constant, until I do a new search again and then it clears out.....is there anyway to do this?
Thankyou in advance for helping this noob out as always :)
Don't worry about the DB connection I tried it out and it works like a charm
so don't worry about if the DB is connecting or if I can retrieve data, because I already tested them out and also displayed it within
a datagrid....so just giving anyone the heads up :)