本文修改來源:http://www.cnblogs.com/chenyuming507950417/p/3169267.html
假如Excel中的數據如下:
數據庫建表如下:
其中Id為自增字段:
代碼:
Page_Load( FileSvr fileSvr = System.Data.DataTable dt = fileSvr.GetExcelDatatable(, System.Data.DataTable GetExcelDatatable( fileUrl, cmdText = System.Data.DataTable dt = OleDbConnection conn = OleDbConnection( (conn.State == ConnectionState.Broken || conn.State == System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, sheetName = schemaTable.Rows[][ strSql = + sheetName + OleDbDataAdapter da = DataSet ds = dt = ds.Tables[ i = lng = lat = offsetLNG = offsetLAT = (DataRow dr lng = dr[ lat = dr[ offsetLNG = dr[ offsetLAT = dr[ strSql = .Format( strConnection = ConfigurationManager.ConnectionStrings[ SqlConnection sqlConnection = SqlCommand sqlCmd = sqlCmd.CommandText = sqlCmd.Connection = SqlDataReader sqlDataReader = i++ }
運行結果: