单值数据的会话来自数据库,而双值数据不会到来 [英] Session for single value data is getting from database and for double value data is not coming

查看:69
本文介绍了单值数据的会话来自数据库,而双值数据不会到来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

This is my code

using (SqlCommand cmd = new SqlCommand("select * from Products where cast(ProductID as nvarchar(100)) in ('" + Session["Products"] + "')", con))


//Here when Seccion["Products"] value is 1 ,Data is coming and is entering in to while loop

//When Session["Products"] value is 1,2 ,while loop is not entering what is my problem with this code  Plz can u suggest me 
 
                  {
                      con.Open();
                      using (SqlDataReader sdr = cmd.ExecuteReader())
                      {
                          while (sdr.Read())
                          {
                              customers.Add(new ProductsData());
                              customers[customers.Count - 1].ProductID = Convert.ToInt32(sdr["ProductID"].ToString());
                              customers[customers.Count - 1].CategoryID = Convert.ToInt32(sdr["CategoryID"].ToString());
                              customers[customers.Count - 1].Title = sdr["Title"].ToString();
                              customers[customers.Count - 1].ThumbNail = sdr["ThumbNail"].ToString();
                              customers[customers.Count - 1].IsActive = Convert.ToBoolean(sdr["IsActive"].ToString());
                              customers[customers.Count - 1].FlashPath = sdr["FlashPath"].ToString();
                              customers[customers.Count - 1].Price = Convert.ToDouble(sdr["Price"]);
                              customers[customers.Count - 1].Description = sdr["Description"].ToString();
                              //customers[customers.Count - 1].CustomerID = Convert.ToInt32(sdr["customer_id"]);
                              //customers[customers.Count - 1].FirstName = sdr["firstname"].ToString();
                              //customers[customers.Count - 1].LastName = sdr["lastname"].ToString();
                          }
                          con.Close();
                          //return customers;
                      }
                  }

推荐答案

使用此



use this

"select * from Products where ProductID in (" + Session["Products"] + ")"


这篇关于单值数据的会话来自数据库,而双值数据不会到来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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