Solved

Dynamically fill textbox from Access

Posted on 2004-04-29
7
295 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write to file when application closes (by logoff) - VB.NET 1 37
VB.NET Repostiory Pattern 7 49
vb.net class 3 21
System.net.Sockets Error 5 26
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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