在c#如何将listview中的数据保存到数据库中的表中

在c#如何将listview中的数据保存到数据库中的表中,第1张

private void listView1_Click(object sender, EventArgs e)//listview点击事件

{

if (this.listView1.SelectedItems == null) return

ListViewItem item = this.listView1.SelectedItems[0]//选中的ltem

if (this.comboBox1.SelectedIndex == -1) return

if (item == null) return

//把每一项里的值取出来

string a = item.SubItems[0].Text.ToString()

string b = item.SubItems[1].Text.ToString()

string c = item.SubItems[2].Text.ToString()

string d = item.SubItems[3].Text.ToString()

}

然后你用ADO连接数据库,写insert语句,把取出来的值当参数传给SQL语句。就可以了 思路大概是这样的,希望你帮助你~

就是写文件啊,循环list string str = Guid.NewGuid().ToString()string strPath = "C:\\Program Files\\" + str + ".xls"FileStream fs = File.Create(strPath)StreamWriter sw = new StreamWriter(fs, Encoding.Unicode)string strLine = ""// 写入列标题 for (int i = 0i <colNames.Lengthi++) { string[] col = colNames[i].Split('=')strLine = strLine + col[1].ToString() + Convert.ToChar(9)} sw.WriteLine(strLine)strLine = ""// 写入报表数据 for (int i = 0i <dt.Rows.Counti++) { // for (int j = 0j <colNames.Lengthj++) { string[] col = colNames[j].Split('=')strLine = strLine + dt.Rows[i][col[0]].ToString() + Convert.ToChar(9)} sw.WriteLine(strLine)strLine = ""} sw.Close()fs.Close()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6843841.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-29
下一篇 2023-03-29

发表评论

登录后才能评论

评论列表(0条)

保存