在网格thorungh查询字符串中显示数据时出现问题. [英] Problem in Displaying data in grid thorungh querystring.

查看:50
本文介绍了在网格thorungh查询字符串中显示数据时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将id从主页重定向到productcatalog.aspx页面..在productcatalog.aspx页面上.

在productcatalog.aspx页上.我写了一个查询

i am redirecting the ids from main page to productcatalog.aspx page.. on productcatalog.aspx page.

On productcatalog.aspx page . i have written a query

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



我可以将Request.querystring ["id"].tostring设置为字符串,还是应该将其设置为numaric ...

在调试器中,我从主页获取ID..



Can i pas Request.querystring["id"].tostring as string or i should pas it in as numaric...

and in debugger i am getting the ids from the main page as..

query	"Select * from Products where ProductID= ',63,64,65' AND UnitCost < 5000"	string



但是数据没有显示在网格中..问题是如何解决这个问题.

是他们在生成的查询中出了点问题..

在主页上,我做出了如下逻辑..



but data is not shown in grid.. what is the problem how to sort out that one.

is their something wrong in generated query..

on the main page i have made a logic as below..

tring querydr = "select * from Products";
           SqlDataReader dr = obj.fillcomb(querydr);
            
            while (dr.Read())
            {
                 
                if(proid == String.Empty)
                  {
                 proid =  dr["ProductID"].ToString(); 
                 }
              else
                 {
                     proid += "," + dr["ProductID"].ToString();
                }
 
 
                }
            
          
 
       Response.Redirect("ProductCatalog.aspx?ID="+proid);

推荐答案

您可以在查询字符串中传递字符串.那不是问题.
问题出在查询本身.
You can pass string in your query string. That is not the problem.
The problem is with the query itself.


您不能对多个值使用相等性,因此要使用
You cannot use equality for multiple values so instead of having
...where ProductID= ',63,64,65'...


你应该写


you should write

...where ProductID IN (63,64,65)...


(因为值在数据库中是数字的)


(Taken that the values are numerical in the database)


这篇关于在网格thorungh查询字符串中显示数据时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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