使用多个查询将数据填充到网格中的混乱 [英] confusion in filling the data in grid with multiple queries

查看:53
本文介绍了使用多个查询将数据填充到网格中的混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将产品ID从主页发送到productcatalog.aspx,然后基于这些ID生成查询以在网格中显示数据. 我在页面上有不同的链接..一个链接是价格< 5000,一个链接是价格在5000到1000之间.我将休假代码放入5000链接事件中.在主页上.


i am sending productids from mainpage to productcatalog.aspx and then generating the query on the bases of these ids to show data in grid..
i have different links on page.. one link is Price <5000 and one link is Price between 5000 and 1000. i put the fallowing code in 5000 link event. on main page.


while (dr.Read())
{
   if(proid == String.Empty)
   {
      proid =  dr["ProductID"].ToString(); 
   }
   else
   {
      proid += "," + dr["ProductID"].ToString();
   }
}



我想对主页上的价格5000至1000之间的链接执行相同的步骤

但我有一个问题,无法根据不同链接在productcatalog.aspx页中显示数据.

对于价格低于< 5000的产品,我编写了可以正常工作的代码,如下所示

仅在页面加载时,我在此查询的基础上使用数据适配器填充网格



i want to do the same procedure for link between of price between 5000 to 1000 which is on main page

but i have a problem of showing the data in productcatalog.aspx page on the bases of different links.

for products price <5000 i have written the code which works fine is as below

just on page load i fill the grid using data adapter on the base of this query

string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() +"' AND UnitCost < 5000";



我要怎么做才能在5000和10000之间再次查询UnitCost

即查询如下.



what i have to do to put another query for UnitCost between 5000 and 10000

i.e the query would be as below.

string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() +"' AND UnitCost between 5000 and 10000"



但是我该如何在productcatalog.aspx中编写该查询.这样两个查询都能正常工作.



but how can i write that query in productcatalog.aspx. so that both queries works fine.


推荐答案

嗨farooq,


请按照以下代码更改查询

hi farooq,


please change the query as per below code

string query = "Select * from Products where ProductID in (" + Request.QueryString["ID"].ToString() +") AND UnitCost < 5000";



在这里,如果ProductID字段具有int数据类型,则查询变得像

(1,2,3,4,5)中的productID像这样,

并且如果productID字段具有varchar数据类型或nvarchar数据类型,则

productId in(''1'',''2'',''3'',''4'')

希望这个解决方案能对您有所帮助....:)



here , if ProductID field has int datatype then query become like

productID in (1,2,3,4,5) like this,

and if productID field has varchar datatype or nvarchar datatype then

productId in (''1'',''2'',''3'',''4'')

hope this solution will help....:)


这篇关于使用多个查询将数据填充到网格中的混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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