Solved

Dynamically fill textbox from Access

Posted on 2004-04-29
7
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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