Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
m@dhu 7-Apr-11 2:53am    
not clear.
Mahendra.p25 7-Apr-11 2:55am    
with Query string You can get the Value on the basis of which you can retrieve your record from the database based on that Value.
SURBHI TYAGI 7-Apr-11 3:00am    
Ok sir...
plz give any example...

Thanku sir..

Take Your Query string Value in variable
MIDL
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>
 
Share this answer
 
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");
}

In Default2.aspx i am taken one gridview control.

I hope work this.
 
Share this answer
 
Comments
SURBHI TYAGI 7-Apr-11 3:27am    
hi,
my work as:-
database:dept
two columns:-dnum,dname
Default.aspx has one dropdown and default2.aspx has one textbox.
nw i have connect dropdown to database and i want when i select a dept in dropdown then on next page textbox shows the value(dnum) of that dept.
Rakesh From Patna 7-Apr-11 3:41am    
now you first dropdownlist you select autopostback property is true. now douple click the dropdown list then you write the code
response.redirect("default2.aspx?dname=" + dropdown.selecteditem.text/*(or value which require)*/ );
now you default2.aspx page reterive the value form database in use of query string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900