ADO.Net:向程序传递查询字符串
2004-11-14 23:19
495 查看
页面query.aspx可以根据传递的id参数在数据库中进行查询,如: http://gqa-eric-lv/aspnet/MyBBSQuery/query.aspx?id=26 程序中可以使用this.Request.QueryString["ID"]获取查询字符串ID的值,如下例:
SqlConnection coreDB=new SqlConnection();
coreDB.ConnectionString= "workstation id=/"GQA-ERIC-LV/";packet size=4096;integrated security=SSPI;" +
"data source=/"gqa-eric-lv/";persist security info=False;initial catalog=CoreDB";
int QueryID=3;
string idStr=TextBox2.Text.Trim();
QueryID=Convert.ToInt32(this.Request.QueryString["ID"]);
if(QueryID<0||TextBox2.Text.Trim()!="")return;
string mySelectQuery = "SELECT ID,Title,Content FROM myBBS where id="+QueryID;
SqlCommand myCommand = new SqlCommand(mySelectQuery,coreDB);
coreDB.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
TextBox1.Text=myReader["title"].ToString();
TextBox2.Text=myReader["ID"].ToString();
TextBox3.Text=myReader["content"].ToString();
}
}
finally
{
myReader.Close();
coreDB.Close();
}
SqlConnection coreDB=new SqlConnection();
coreDB.ConnectionString= "workstation id=/"GQA-ERIC-LV/";packet size=4096;integrated security=SSPI;" +
"data source=/"gqa-eric-lv/";persist security info=False;initial catalog=CoreDB";
int QueryID=3;
string idStr=TextBox2.Text.Trim();
QueryID=Convert.ToInt32(this.Request.QueryString["ID"]);
if(QueryID<0||TextBox2.Text.Trim()!="")return;
string mySelectQuery = "SELECT ID,Title,Content FROM myBBS where id="+QueryID;
SqlCommand myCommand = new SqlCommand(mySelectQuery,coreDB);
coreDB.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
TextBox1.Text=myReader["title"].ToString();
TextBox2.Text=myReader["ID"].ToString();
TextBox3.Text=myReader["content"].ToString();
}
}
finally
{
myReader.Close();
coreDB.Close();
}
相关文章推荐
- 关于csc中"/res"参数的奇怪问题
- 想要做的几件事情
- 生:生活
- ADO.Net:使用DataReader向数据库中插入数据
- 终于有了自己的blog,发文庆祝一下
- 反思
- ADO.Net:从DataReader中获取数据表的Schema信息
- 写ASP时常用到的一些函数
- 尝鲜微软新桌面主题——Energy Blue
- 用商业智能深入研究数据
- SQL注入路径问题 作者:孤光剑隐
- 兰陵王•柳阴直
- 国外生活必备的英文词汇2
- 尝鲜微软新桌面主题——Energy Blue
- 国外生活必备的英文词汇1
- 跨站Script攻击 Author: Hoky.pRo
- ASP.NET POST方式提交数据!
- Map的实现
- ASP.NET GET 方式提交数据!
- 电子商务之路