标题:如何读取数据库同一列里符合要求的多行数据
只看楼主
wuqinghao10
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-1-16
结帖率:0
 问题点数:0 回复次数:1 
如何读取数据库同一列里符合要求的多行数据
举例:
public string getAccessories(string productName, int pnPass1, int pnPass2)
        {
           string accessories = "";

            SQLiteConnection conn = new SQLiteConnection("Data Source=database/HexSettings.db;");
            conn.Open();
            SQLiteCommand cmd = new SQLiteCommand(conn);

            if (productName.Contains("A"))
            {
                = "select CC from List1 where ProductName ='" + productName + "' and LPN =" + pnPass1 + " and HPN =" + pnPass2;
            }
            else
            {
                = "select CC from List2 where ProductName ='" + productName + "' and PNPass1 =" + pnPass1 + " and PNPass2 =" + pnPass2;  
            }
             = CommandType.Text;
            SQLiteDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                accessories = dr[0].ToString();
            }

            dr.Close();

            return accessories;

        现在我只能读取符合要求的第一个值,请问各位如何修改可以读取符合要求的所有值
谢谢!!
搜索更多相关主题的帖子: database 数据库 public where 数据库 database public where 
2013-05-15 11:21
shangsharon
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
威 望:7
帖 子:221
专家分:1261
注 册:2012-3-25
得分:0 
if (dr.Read())
            {
                accessories = dr[0].ToString();
            }


把if改成while

while(dr.read())
{
//读完一列加个分隔符吧
accessories+=dr[0].tostring()+"|";
}
2013-05-15 13:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-407126-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.746965 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved