日期:2014-05-17  浏览次数:20849 次

查询数据库后。如何放入后台代码的变量中
C# Winfrom 中。我们经常会用SQL 的Select 来查询我们要的数据。通过Select查询需要多值。放入一个 数组变量中 如:
select id,[name],VIPID,Money from Customers where Money > 15000.00
这里查询到多值。现在放入一个String[] Customer数组中。
请高手指点一二。谢谢

------解决方案--------------------
你那个是好几个字段,难道都放到一个数组里,还是想定义一个多维数组
------解决方案--------------------
唉,你搞一个实体类,将你要查询的列作为实体类里面的字段
然后用集合去装你所谓的多值放进去

List<实体类> d = new List<实体类>();

这样不就ok了么

类似这种,用循环读取的方式放入实体类


C# code
    public static List<AriticleGroup> SearchGroupNameByUserId(int userId)
        {
            List<AriticleGroup> groups = new List<AriticleGroup>();
            string sql = string.Format("select groupId,groupName from AriticleGroup where userId={0}", userId);
            SqlDataReader reader = ConnectionSQL.ExecuteSelect(sql);
            AriticleGroup group = null;
            while (reader.Read())
            {
                group = new AriticleGroup();
                group.AriticleGroupId = (int)reader["groupId"];
                group.AriticleGroupName = reader["groupName"].ToString();
                groups.Add(group);
            }
            reader.Close();
            ConnectionSQL.CloseConn();
            return groups;
        }