双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

读入数据到list,哪里不对

20004 20004 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using (SqlConnection con = new SqlConnection(ConnectString))
{
try
{
DataSet ds = new DataSet();
SqlCommand cmd=new SqlCommand (sql,con);
SqlDataReader dr = cmd.ExecuteReader();

int nFields = dr.FieldCount;
lv.Clear();

for (int i = 0; i < nFields ; i++)
{
lv.Columns.Add(dr.GetName(i), 100, HorizontalAlignment.Left);
}

int nRow = 0;
while (dr.Read())
{
// Create an array of subitems for quick insertion
// The subitems will be all fields in the row except for
// the first field
String[] subitems = new String[nFields];
for (int i = 0; i < nFields; i++)
{
subitems[i] = dr[i].ToString();
}

// Insert a new item into the listview, and add the subitems at
// the same time. The item will be the first field in the row
ListViewItem item = new ListViewItem(subitems, -1);
lv.Items.Add(item);
++nRow;
}
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
...全文

相关推荐

python实现将读入的多维list转为一维list的方法

第一种:使用extend() >>> lines = open('test.txt').readlines() >>> lines ['1\n', '2\n', '3\n', '4,5\n'] >>> for line in lines: ... ll.extend(line.strip().split(',')) ... >>> ll ['1', '2', '3', '4', '5'] 第二种:使用+ >>> ll = [] >>> lines = open('test.txt').readlines() >>> lines ['1\n', '2\n', '3\n', '4,5\n']

weixin_38639747

Python3 中把txt数据文件读入到矩阵中的方法

下面小编就为大家分享一篇Python3 中把txt数据文件读入到矩阵中的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

weixin_38662122

pandas DataFrame数据转为list的方法

下面小编就为大家分享一篇pandas DataFrame数据转为list的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

weixin_38503483

mybatis 批量将list数据插入到数据库的实现

主要介绍了mybatis 批量将list数据插入到数据库的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

weixin_38712899

java list 转换为json数据

java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据java list 转换为json数据

yangtyty0011
评论 7
收藏 已收藏
分享
返回顶部
20004
C# 111,129 成员 642,540 内容