如何将查询字符串值传递给sqldatasource [英] how to pass query string value to the sqldatasource

查看:76
本文介绍了如何将查询字符串值传递给sqldatasource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面的URL看起来像http://domain/default.aspx?ID=1,我需要将ID值传递给codeBehind中数据源的SELECT语句.

有人可以帮我吗?

The URL of the page will look like http://domain/default.aspx?ID=1 and I need to pass the ID value to the SELECT statement of the datasource in the codeBehind.

Can someone help me out with that?
Thanks!

推荐答案

如果使用SqlDataCommand执行SELECT语句,则可以在该对象上添加参数.参见示例:

在您的代码后面.
If you are using SqlDataCommand to execute your SELECT statement, then you can add parameters on that object. See example:

On your code behind.
sqlDataComm.Parameters.AddWithValue("@id", Request.QueryString[ID]);



在您的SELECT语句上.



On your SELECT statement.

SELECT * FROM yourTable WHERE ID = @id


这篇关于如何将查询字符串值传递给sqldatasource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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