Solved

Dynamically fill textbox from Access

Posted on 2004-04-29
7
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Did this help you?

Bob
0
 

Author Comment

by:ClassickJr
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now