list存儲數據
㈠ 怎麼將list<>保存到資料庫中
就是寫文件啊,循環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 = 0; i < colNames.Length; i++) { string[] col = colNames[i].Split('='); strLine = strLine + col[1].ToString() + Convert.ToChar(9); } sw.WriteLine(strLine); strLine = ""; // 寫入報表數據 for (int i = 0; i < dt.Rows.Count; i++) { // for (int j = 0; j < colNames.Length; j++) { string[] col = colNames[j].Split('='); strLine = strLine + dt.Rows[i][col[0]].ToString() + Convert.ToChar(9); } sw.WriteLine(strLine); strLine = ""; } sw.Close(); fs.Close();
㈡ 資料庫中用什麼類型存儲List
List類型本身是可以存放任何對象的,也就是只要是數據都可以存儲的。
如:List.add(new Object());這個語句是不會報錯的。由於Object是任何對象的父類,所以任何的子對象都是可以被List通過add方法進行存放的。