Subject: Populating a textbox using results of a query
Posted By: ricweb Post Date: 12/7/2006 5:01:16 PM
Trying to do something that seems like it should be really simple, but I'm new to VB (All my development has been asp). I have a form with 4 text boxes: Quantity, Sku, Description, Week, Year.

The user enters the quantity, then the sku. As soon as they leave the sku field, I want to look up the description from a table in the database and place it in the Description field, they then enter the week and year, and upon clicking a button, everything is added to a different table in the database.

It seems like it should be an easy thing to fire a stored procedure once the focus goes on the description box,(taking a parameter from the sku field and looking up the description) and throwing the result into the description textbox, but I can't figure out how to do it yet. I'm sure I'll figure it out, but it's really frustrating to find my way around in this new environment.

Reply By: anubisascends Reply Date: 12/7/2006 7:51:10 PM
imports system.data.oledb
Public Class Form1

Dim theCommand as new oledbCommand
Dim theConnection as new oledbConnection
Dim teQuery as String

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus

theConnection.connectionstring = [connectin string as a string value]

theCommand = new oledbcommand(theQuery, theConnection)

theCommand.Connection.open()

Dim reader as oledbdatareader = theCommand.executereader(commandbehavior.singlerow)

reader.read()

textbox1.text = reader(0)

theCommand.Connection.Close()

end sub

End Class

hope this helps.

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Albert Einstein
US (German-born) physicist (1879 - 1955)

Go to topic 53297

Return to index page 99
Return to index page 98
Return to index page 97
Return to index page 96
Return to index page 95
Return to index page 94
Return to index page 93
Return to index page 92
Return to index page 91
Return to index page 90