class Program
{
static void Main(string[] args)
{
string excelPath = @"C:\Documents and Settings\lg39304\My Documents\Project Document\SafeSQL Issues\aa.xls";
string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelPath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
OleDbConnection con = new OleDbConnection(conStr);
con.Open();
string sql = "select * from [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader dr = cmd.ExecuteReader();
SqlConnection sqlCon = new SqlConnection("Server=Test; Database=DRMS;User ID=abc;Password=123");
sqlCon.Open();
using (SqlBulkCopy bukCopy = new SqlBulkCopy(sqlCon))
{
bukCopy.NotifyAfter = 20;
bukCopy.DestinationTableName = "version";
bukCopy.WriteToServer(dr);
}
}
}
SQL Bulk-copy from Excel
最新推荐文章于 2023-07-21 16:31:19 发布