Sql - fill textboxes

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.
VBdotnet2005Asked:
Who is Participating?
 
af4643Commented:
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
con.open
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.close

con = nothing
0
 
af4643Commented:
thanks for the accept, but why do I get just a "B" grade?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.