在VB中绑定表数据 [英] bind table data in vb

查看:69
本文介绍了在VB中绑定表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在文本框中输入名称时,我需要获取地址标签.我的代码是这样的

I need get address to lable when I enter name into textbox. My code is like this

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



不幸的是,它不起作用.否则我看不到eny错误.

然后,我尝试按年龄搜索信息.它的工作.但是我不知道在那里输入名字时会得到地址.
我正在使用vb.net和sql server.



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.

推荐答案

事物对!

1.查看参数化查询,它将保护您免受SQL注入的影响

阅读/示例: SQL参数化查询示例 [ ^ ]

2.您有一个Try Catch块,但是您只是退出了子!就像其他人所说的那样,如果发现任何错误,请对错误进行处理.

3.试试这个

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

 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()


输入代码,您将看到错误;)
Put the code and you will see the error ;)
catch ex as exception
messagebox.show(ex.message)
end try


这篇关于在VB中绑定表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆