Pho3nix
The Legend
Pretty tired and making stupid mistakes.
Pretty simple in code (at least it should be ) but something seems to be wrong somewhere
Some help would really be appreciated.
Pretty simple in code (at least it should be ) but something seems to be wrong somewhere
Some help would really be appreciated.
Code:
public void Main()
{
try
{
string conn = Dts.Variables["User::DestinationString"].Value.ToString();
OleDbDataAdapter A = new OleDbDataAdapter();
System.Data.DataTable dt = new System.Data.DataTable();
A.Fill(dt, Dts.Variables["User::Variable"].Value);
CreateTABLE(conn , "Data", dt);
MessageBox.Show("Success");
}
catch (Exception ex)
{
MessageBox.Show("Error:"+ex.Message.ToString());
}
// TODO: Add your code here
Dts.TaskResult = (int)ScriptResults.Success;
}
public static void CreateTABLE(string connectionString, string tableName, DataTable table)
{
string sqlsc;
using (SqlConnection connection = new SqlConnection(connectionString))
{
if (connection.State == ConnectionState.Closed)
connection.Open();
SqlCommand sqlCom = null;
sqlsc = "CREATE TABLE " + "[" + tableName + "]"+"(";
for (int i = 0; i < table.Columns.Count; i++)
{
sqlsc += "[" + table.Columns[i].ColumnName + "] ";
if (table.Columns[i].DataType.ToString().Contains("System.Int32"))
sqlsc += " [int] ";
else if (table.Columns[i].DataType.ToString().Contains("System.DateTime"))
sqlsc += " [datetime] ";
else
sqlsc += " nvarchar(500)";
sqlsc += ",";
}
sqlsc += sqlsc.Substring(0, sqlsc.Length - 1) + ")";
sqlCom = new SqlCommand(sqlsc, connection);
sqlCom.ExecuteScalar();
connection.Close();
}
}
