C中数据导出到Excel表格(15)
时间:2025-04-05
时间:2025-04-05
DataGridView 数据导出到Excel
51. OleDbConnection objConn = new OleDbConnection(connString);
52. OleDbCommand objCmd = new OleDbCommand();
53. objCmd.Connection = objConn;
54. //mandText=sb.ToString();
55.
56. try
57. {
58. objConn.Open();
59. //objCmd.ExecuteNonQuery();
60. }
61. catch(Exception e)
62. {
63. return "在Excel中创建表失败,错误信息:" + e.Message;
64. }
65.
66. sb.Remove(0,sb.Length);
67.
68. sb.Append("INSERT INTO ");
69. sb.Append(dt.TableName + " ( ");
70.
71. for(int i=0;i<cols;i++)
72. {
73. if(i < cols - 1)
74. sb.Append(dt.Columns[i].ColumnName + ",");
75. else
76. sb.Append(dt.Columns[i].ColumnName + ") values (");
77. }
78.
79. for(int i=0;i<cols;i++)
80. {
81. if(i < cols - 1)
82. sb.Append("@" + dt.Columns[i].ColumnName + ",");
83. else
84. sb.Append("@" + dt.Columns[i].ColumnName + ")");
85. }
上一篇:红楼梦人物描写风格浅析
下一篇:美国联邦制的发展。