怎么将list<>保存到数据库中

怎么将list<>保存到数据库中,第1张

就是写文件啊,循环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()

先声明一个你要添加的表实体类

public class  student

{

   public int id{getset}

   public string name{getset}

}

List<student>st=new List<student>()

foreach(var item in st)

{

    Model.student st=new Model.student()

    st.id=item.id

    st.name=itemt.name

    this.Insert(st)

}

//根据实体添加数据库

public string Insert(Model.student student)

{

.... *** 作数据库

}


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

原文地址:https://54852.com/sjk/6850744.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存