使用查询字符串时如何使用数据库? [英] how to work with database when we are using querystring?

查看:94
本文介绍了使用查询字符串时如何使用数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生/妈妈,您好,
我要问的是,在使用查询字符串时我们将如何处理数据库?
请给我一个例子,帮助我并解释一下.

Hello sir/mam,
I am to ask that how we will work with database while using querystring?
Plz help me and explain by giving any example.

推荐答案

获取查询字符串值在变量中
Take Your Query string Value in variable
int Id = int.Parse(Request.QueryString["ID"]);


 pass that to a function to get records based on that id
 
 Call that Function 

fn_getProductlistDetailsBasedOnCategoryId(id);


public void fn_getProductlistDetailsBasedOnCategoryId(int Id)
{
  //Your Code
}

</pre>


您可以尝试以下操作:-
在sql表结构中:-
表格名称:-User
名称角色密码
拉克什(Rakesh)1123
王子2123

现在在Default.aspx中,我使用一个文本框和一个按钮.
现在,当我们单击按钮时,它将在default2.aspx页中发送文本框值.
语法用于重定向到default2.aspx是 Response.Redirect(〜/Default2.aspx?uId ="+ textbox1.Text);

现在,在default2.aspx页中,我们编写page_load事件
You try this:-
In sql table structure :-
Table Name:-User
Name role Password
Rakesh 1 123
Prince 2 123

Now in Default.aspx i am use a text box and one button .
now when we click the button it send the text box value in default2.aspx page.
Syntax is use for redirect to default2.aspx is Response.Redirect(~/Default2.aspx?uId=" + textbox1.Text);

Now in default2.aspx page we write page_load event
if(!page.ispostback)
{
if(request.querystring["uID"].ToString()!=null)
{
System.Data.SqlClient.Sqlconnection con=new sqlconnection(//Connectionstring);
System.Data.SqlClient.SqlDataAdapter adapter=new sqldataadapter("Select * from User where Name=''" + request.querystring["uID"].ToString() + "''",con);
DataSet ds=new Dataset();
adapter.fill(ds);
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
}
else
  Response.Write("No query string send");
}


在Default2.aspx中,我采用了一个gridview控件.

我希望可以这样做.


In Default2.aspx i am taken one gridview control.

I hope work this.


这篇关于使用查询字符串时如何使用数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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