|
批量复制 |
|
|
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Data.SqlClient;
namespaceBulkCopy
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidbtnCopy_Click(objectsender,EventArgse)
{
using(SqlConnectionconn=newSqlConnection(ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString))
{
conn.Open();
using(SqlCommandcomm=newSqlCommand())
{
comm.Connection=conn;
comm.CommandText="SelectfromStudent";
SqlDataReaderread=comm.ExecuteReader();
using(SqlConnectiondesconn=newSqlConnection(ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString))
{
desconn.Open();
using(SqlBulkCopybulkcopy=newSqlBulkCopy(desconn))
{
bulkcopy.DestinationTableName="Temp_Student";
try
{
bulkcopy.WriteToServer(read);
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
MessageBox.Show("DataHasBeenSuccessfullyCopied");
}
}
}
|
|
|
|
|
|
|
|
|
|
|