So I have this chunk of code that uploads data tables to a data base table.
public bool TableCreator(DataTable dt, string tableName)
{
using (SqlConnection con = new SqlConnection(connectionString))
{
try
{
/*#### Method needs to include adding apropreate amount of colunm headers ####*/
string colunmHeader = " (TestColunmHeader varchar(50));";
//Opens connection to the DataBase
con.Open();
//Creates a new Table in the Database
using (SqlCommand command = new SqlCommand("CREATE TABLE " + tableName + colunmHeader, con))
command.ExecuteNonQuery();
UploadConnection(dt, tableName);
return true;
}
catch (Exception)
{
return false;
}
}
}
This works great if I "Hard Code" the column names and amounts but I need the new table that's created in the database to have the same number of columns as the dataTable.
I have tried a few things but I'm just lacking the knowledge to do this.