Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need get address to lable when I enter name into textbox. My code is like this
VB
ds.clear
da=new sqldataadapter("SELECT * FROM members WHERE name=" & textbox1.text &"", dbconn)
try
da.fill(ds,"members")
bind()
catch ex as exception
exit sub
end try

sub bind()
lable1.databindings.add("text",ds,"members.memname")
end sub


Unfortunately its not working. Otherwise I can't see eny errors.

Then i try search infomation by there age. its worked. but I have no idea to get address when emter there names.
im using vb.net and sql server.
Posted
Updated 3-Feb-12 5:36am
v2

Couple of things!

1. Look at parameterised Queries it will protect you against SQL Injection

Read / Example : SQL Parameterised query example[^]

2. you have a Try Catch block, but you just exit the sub! as others have stated you need to, if any errors are trapped do something with the error.

3. Have a try of this

VB
 dim dt as Datatable = ds.table(0)
 dim dr as Datarow = dt.rows(0)

'I have assumed that the values you are after are in column 1, it is considered better practice to replace the ordinal number with its name
 Label1.text = dr(0).toString()
 
Share this answer
 
Put the code and you will see the error ;)
VB
catch ex as exception
messagebox.show(ex.message)
end try
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900