In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces asp.net how to import data from DataTable to Excel file and create a table. It is very detailed and has a certain reference value. Interested friends must read it!
The details are as follows:
/ Import data from DataTable into Excel file / data source / absolute path of Excel file / the column name / Excel in the corresponding column name / TBL returned True successfully, and failed to return Falsepublic static bool ExportDataToExcel (DataTable dataTable, string AbsoluteExcelFilePath, string [] TblColName, string [] ColumnName) {int k = 0; if (dataTable = null) return false; OleDbConnection Conn = new OleDbConnection () Try {string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AbsoluteExcelFilePath + "; Mode=Share Deny None;Extended Properties=Excel 8.0 + Jet OLEDB:Create System Database=True"; Conn = new OleDbConnection (strConn); Conn.Open (); OleDbCommand command = Conn.CreateCommand (); string strSQL = ""; if (dataTable.Columns! = null) {/ / build table strSQL = "CREATE TABLE" + dataTable.TableName + "("; for (int I = 0; I)
< ColumnName.Length; i++) { strSQL += ColumnName[i] + " TEXT,"; } strSQL = strSQL.Substring(0, strSQL.Length - 1); strSQL += ")"; command.CommandText += strSQL; command.ExecuteNonQuery(); if (dataTable.Rows.Count >0) {/ / Import data foreach (DataRow row in dataTable.Rows) {strSQL = "insert into" + dataTable.TableName + "("; for (k = 0; k < TblColName.Length; kits +) {strSQL + = ColumnName [k] + ",";} strSQL = strSQL.Substring (0, strSQL.Length-1); strSQL + = ") values ("; for (k = 0; k < TblColName.Length) Exception ex +) {strSQL + = "'" + row [TblColName] + ",";} strSQL = strSQL.Substring (0, strSQL.Length-1); strSQL + = ")"; command.CommandText = strSQL; command.ExecuteNonQuery ();} catch (Exception ex) {Conn.Close (); throw new Exception (ex.Message); return false;} Conn.Close (); return true;}
Call method:
DataSet ds = (DataSet) Session ["listMobile"]; / / get the value if (ds.Tables [0] .Rows.Count) of the table to be exported
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
This article mainly introduces the "HTML basic single page case analysis" related knowledge, the editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "HTML basic single page case analysis" article can help you solve the problem.
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.