Murray Brown
asked on
C# SQL BulkCopy class create SQL table if not there
Hi
I use the following code to upload data from a data table to a SQL table calling the Bulk Copy class
If the SQL table is not there then I want to automatically create it. How do I update my code
to do this?
DataTable tableDataTable = oDataSet.Tables[0];
string conString = "Server = localhost; Database = Test1; Trusted_Connection = Yes;";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
Create_Table();
sqlBulkCopy.DestinationTab leName = "MTEST";
sqlBulkCopy.BulkCopyTimeou t = 0;
//Indefinite when zero
con.Open();
sqlBulkCopy.WriteToServer( tableDataT able);
con.Close();
}
}
I use the following code to upload data from a data table to a SQL table calling the Bulk Copy class
If the SQL table is not there then I want to automatically create it. How do I update my code
to do this?
DataTable tableDataTable = oDataSet.Tables[0];
string conString = "Server = localhost; Database = Test1; Trusted_Connection = Yes;";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
Create_Table();
sqlBulkCopy.DestinationTab
sqlBulkCopy.BulkCopyTimeou
//Indefinite when zero
con.Open();
sqlBulkCopy.WriteToServer(
con.Close();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What the Create_Table() does?
ASKER
That is code to create a table using a SQL statement that I used to test alternatives. Please ignore it in this post
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both