We help IT Professionals succeed at work.

Sql - fill textboxes

VBdotnet2005 asked
Medium Priority
Last Modified: 2010-04-23
I have four textboxes : txtClientId, txtAccountNumber, txtPhoneNum, txtFormNum.
I want to retrieve info. from my SQL database and and fill these textboxes. I want a user to enter ClientId, sample, "S14523", and click a btnGet, to retreived info. A link to similiar sample is fine.
Watch Question

Create a stored procedure that accepts the parameter for the ClientID that returns the 4 values.

In your btnGet_Click sub:
Dim con as sqlconnection = new sqlconnection("[connection string]")
Dim cmd as sqlcommand = new sqlcommand("[stored procedure]", con)
Dim reader as sqldatareader

cmd.commandtype = commandtype.storedprocedure
cmd.parameters.add("@clientid", clientid.text) 'clientid is a text box, and @clientid is the parameter name in your stored procedure
reader = cmd.executereader

reader.read 'this is assuming you'll have only 1 row returning. if there's many, then you'll need to loop this

txtClientID.text = reader("txtClientID")                         'column name is in quotes
txtAccountNumber.text = reader("txtAccountNumber")  'column name is in quotes
txtPhoneNum.text = reader("txtPhoneNum")              'column name is in quotes
txtFormNum.text = reader("txtFormNum")          'column name is in quotes


con = nothing

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

thanks for the accept, but why do I get just a "B" grade?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.