string connstr = "Data Source=192.168.0.202;Initial Catalog=database;User ID=sa;Password=123456;";
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from TSchClass", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connstr))
{
sda.Fill(dt);
bulkCopy.DestinationTableName = "TSchClass";//表名称
try
{
bulkCopy.WriteToServer(dt);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally {
conn.Close();
}
}
}
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from TSchClass", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connstr))
{
sda.Fill(dt);
bulkCopy.DestinationTableName = "TSchClass";//表名称
try
{
bulkCopy.WriteToServer(dt);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally {
conn.Close();
}
}
}