public void toDb(string fileName) { string execelConnectionStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + @";Extended Properties=""Excel 8.0;HDR=YES;"""; try { using (OleDbConnection conn = new OleDbConnection(execelConnectionStr)) { OleDbCommand cmd = new OleDbCommand("select * FROM [Sheet1$]", conn); conn.Open(); using (DbDataReader dr = cmd.ExecuteReader()) { string sqlConnectionString = @"Data Source=数据库服务器;Initial Catalog=数据库名;Persist Security Info=True;User ID=sa;Password=123"; // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "E003"; bulkCopy.WriteToServer(dr); } } } } catch (Exception ex) { ex.ToString(); } }
sqlServer导出到excel
最新推荐文章于 2024-04-01 16:36:14 发布