Solved

Dynamically fill textbox from Access

Posted on 2004-04-29
7
294 Views
Last Modified: 2010-04-24
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.



   
0
Comment
Question by:ClassickJr
  • 3
  • 2
7 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 10953423
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
0
 

Author Comment

by:ClassickJr
ID: 10954663
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
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 50 total points
ID: 11123132
If you have created a data adapter, and generated a data set using the designer, then what you have is a strong-typed data set.  You can access the properties during design-time:

Dim dt As DataSet.t_GallonsPerPound = DaGallons.Tables("t_GallonsPerPound)
Dim dr As DataSet.t_GallonsPerPoundRow = dt.Rows(0)

        txtWG.Text = Dr.Wine.Value
        txtPG.Text = Dr.ProofGallons.Value

Bob

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 11177029
Did this help you?

Bob
0
 

Author Comment

by:ClassickJr
ID: 11214553
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11214983
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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question