如何使用Querystring从数据库中获取不同的信息 [英] How do I use Querystring to grab different information from a database

查看:159
本文介绍了如何使用Querystring从数据库中获取不同的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了查询字符串,现在就说产品页面:



这是在product.cs

int ProductID = Convert.ToInt32(Request.QueryString [pid]);



product.aspx - 以下是设置每个链接的代码,如果您点击以下链接,它将带您进入页面产品及其产品4的唯一

现代战争



您点击产品页面,它会为您提供一个列表关闭产品图片,点击其中一个产品,我希望它转到一个独特的页面,目的是关闭这个,例如individual_product.aspx。我希望这个页面能像上面的个人一样工作.aspx /?pid = 4



如果pid = 4显示来自数据库的大量信息带图像,如果你点击产品2,不同的信息。我只是不确定如何编写代码。我想我创建一个页面,在每个pid中循环,如果pid = 1然后从数据库等获取信息等等。



我总是知道理论但我我正在为如何编码而苦苦挣扎。

任何帮助都会非常棒。

I have set up query string on lets just say for now a product page:

This is in product.cs
int ProductID = Convert.ToInt32( Request.QueryString["pid"] );

product.aspx - Below is the code to set each link, if you click the below link it will take you to a page product and its unique to product 4
Modern Warfare

You click product page it gives you a list with images off products, you click one of the products I want it to go to a unique page for purpose off this lets say individual_product.aspx. I would like this page to work like the above individual_product.aspx/?pid=4

If pid = 4 show one lot of information from the database with images, if you hit product 2 the same goes with different information. I just wasnt sure how I would code this up. I guess I make a page, make a loop through each pid, if pid =1 then grab info 1 from database etc etc.

I always know the theory but I am struggling on how to code it.
Any help would be awesome thanks.

推荐答案

你好michael,


只需通过从数据库中检索它来绑定你的querystring变量。



例如



in .aspx



, / a>





sample.Href =home.aspx?productname =+ product;



其中productname是查询字符串变量,产品是从数据库中检索的值。



或者只是您可以使用数据集绑定多个值。



例如



DataSet ds = objProduct.getProductNames(productId);

if(ds.tables [0] .rows.count> 0)

{

for(i = 0; i< ds.tables [0] .rows.count;> {

sample.Href = ds.tables [0] .rows [0] [productname];

}

}
Hi michael,

simply bind your querystring variable by retrieving it from the database.

for example

in .aspx

,/a>

in codebehind

sample.Href="home.aspx?productname="+product;

where productname is the querystring variable and the product is the value retrieved from the database.

or simply you can use dataset to bind more than one value.

for example

DataSet ds = objProduct.getProductNames(productId);
if(ds.tables[0].rows.count > 0)
{
for(i=0; i<ds.tables[0].rows.count;>{
sample.Href=ds.tables[0].rows[0]["productname"];
}
}


这篇关于如何使用Querystring从数据库中获取不同的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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