使用asp.net动态输入sql查询
我有一个超链接,应该从 sql 数据库打印信息。但我不知道如何将该超链接值赋予 sql 查询。
SqlConnection conn = new SqlConnection("Server=ILLUMINATI;" + "Database=DB;Integrated Security= true");
SqlDataAdapter ADP = new SqlDataAdapter("select * from News where Headlines= au_id", conn);
我想动态获取 au_id 值,单击超链接后任何人都可以帮助我。
就像当我点击标题时我应该得到相应的新闻。
I have a hyperlink which should print information from sql database.But I'm not able to know how to give that hyperlink value to sql query.
SqlConnection conn = new SqlConnection("Server=ILLUMINATI;" + "Database=DB;Integrated Security= true");
SqlDataAdapter ADP = new SqlDataAdapter("select * from News where Headlines= au_id", conn);
I want to get value au_id dynamically can anybody help me with this after clicking on the hyperlink.
Its like when i click on the headlines i should get the corresponding news.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该使用
LinkButton
而不是Hyperlink
控件,因为超链接会将页面重定向到指定的 URL。但 LinkButton 有一个 Click 事件处理程序。单击该按钮即可获取 ID。您的查询将类似于...
但是,如果您使用
参数化查询来避免 SQL 注入攻击
,那就更好了。First of all, you should use a
LinkButton
instead of aHyperlink
control as hyperlink redirects the page to a specified URL. But the LinkButton has a Click Event handler. On that click you can get the ID.Your query will be look like...
But It would be better if you use a
Parameterized query to save yourself from a SQL Injection Attack
.我不确定你到底想要什么,但这是一个简单的例子:
I'm not sure what do you exactly want, but here is simple example :