有時候我們需要經常的將數據集(DataSet)導入到數據庫中
OleDbConnection olecon = new OleDbConnection(
olecon
OleDbDataAdapter oda = new OleDbDataAdapter(
DataSet newds = new DataSet();
try
{
OleDbCommandBuilder cmdbld = new OleDbCommandBuilder(oda);
cmdbld
oda
ds
int rowcount = ds
for (int n =
{
ds
}
ds
oda
}
catch
{
}
oda
oda
olecon
olecon
OleDbDataAdapter
其實也是一條一條的插入更新的
SqlConnection conn = new SqlConnection(sqlConnectString);
conn
SqlBulkCopy sbc = new SqlBulkCopy(conn);
sbc
//將數據集合和目標服務器的字段對應
for (int q =
{
sbc
}
try
{
sbc
}
catch //(Exception ex)
{
//throw ex;
continue;
}
finally
{
ds
conn
sbc
}
這個是不是也比sql insert也好多了
From:http://tw.wingwit.com/Article/program/net/201311/11522.html