Link to home
Start Free TrialLog in
Avatar of ClassickJr
ClassickJr

asked on

Dynamically fill textbox from Access

Hello,

I have a table "t_GallonsPerPound" where there is the following fields: Id, TP as [True Proof], WG as [Wine Gallons] and PG as [Proof Gallons]

I have a form that i am trying to take the value from a txtTP compare it to the database and pull the rest of the information from that record and populate the other two read only text boxes. This happens when the button is clicked

That is if 184 is entered

TP     WG     PG
-----  -----    ----
184   .114   .252

the text boxes fill with those two numbers respectivly.

Since this is my first attempt in VB.net to access a database... i am somewhat lost... Any help. This is what i have so far.

Private Sub btnLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLookup.Click

        DaGallons.SelectCommand.CommandText = "SELECT [ID], [True Proof], [Wine Gallons], [Proof Gallons] FROM t_GallonsPerPound where TrueProof = '" & txtTP.Text & "'"
        MessageBox.Show(DaGallons.SelectCommand.CommandText)  ' This appears ok in the pop-up.
 End Sub
   

 This is where i get stuck.. I dont know how to get the information.. Normally in VB or ASP the above select statement would return 1 record... but i dont know what the syntax is for VB.net r how to reference it to set the values of the textboxs.

This is just one part of an application i am developing.. hopefully i will turn this into

entering the True Proof, automatically looking up the other values, entering everything into another database table, but i suppose one step at a time..

Any help is appreciated.. i assume this is a pretty simple request.



   
Avatar of Dabas
Dabas
Flag of Australia image

Hi ClassickJr:
I assume DaGallons is a DataAdaptor.
You will need to "Fill" a DataSet or DataTable to hold the results of your SQL statement.

I suggest you try the following:

Dim dt as New DataTable

daGallons.Fill(dt)

Dim dr as DataRow = dt.Rows(0)

txtWG = dt.Item("Wine Gallons")
txtPG = dt.Item("Proof Gallons")

Good luck!

Dabas
Avatar of ClassickJr
ClassickJr

ASKER

I tried what you suggested.. and have two things to add.

1, isince i already set up a dataset DsGallons, using the object tool, do i need to create another one.

and 2)

When i put in the code, as such..
Private Sub btnLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLookup.Click

        DaGallons.SelectCommand.CommandText = "SELECT [ID], [True Proof], [Wine Gallons], [Proof Gallons] FROM t_GallonsPerPound where TrueProof = '" & txtTP.Text & "'"
        MessageBox.Show(DaGallons.SelectCommand.CommandText)

        Dim dt As New DataTable
        Dim dr As DataRow = dt.Rows(0)
        DaGallons.Fill(dt)



        txtWG.Text = DsGallons.Item("Wine Gallons")
        txtPG.Text = DsGallons.Item("Proof Gallons")

    End Sub

I get Item not a member of System.Data.DataTable

any thints... also do i have to Fill the DataAdapter on form load?

Thanks much.

Dave
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did this help you?

Bob
Sorry it has taken so long Bob,

I have not yet had a chance to try this yet... This is only a pet project. I will award the points when i can get a chance to try it out. i hope that is ok.
Just trying to keep everything moving, seeing that I am the Cleanup Volunteer for this topic area.  I like to keep a clean ship, ya know!

Thanks,
Bob