C# Help : Save DataSet to DB

Usually (in Oracle at least) loading large amounts of data one-time is exceptionally fast with external tables (structured files)
 
sqlsc = "CREATE TABLE " + "[" + tableName + "]"+"(";
for (int i = 0; i < table.Columns.Count; i++)
{
sqlsc += "[" + table.Columns.ColumnName + "] ";
if (table.Columns.DataType.ToString().Contains("System.Int32"))
sqlsc += " [int] ";
else if (table.Columns.DataType.ToString().Contains("System.DateTime"))
sqlsc += " [datetime] ";
else
sqlsc += " nvarchar(500)";
sqlsc += ",";

}


For the love of god man, at least use stringbuilders when concatenating strings. You'll thank me later :3
 
OleDbDataAdapter A = new OleDbDataAdapter();


"A"? Really now?

I think you need to clean up a lot of code once you got this working.

For the love of god man, at least use stringbuilders when concatenating strings. You'll thank me later :3

+1
 
using (SqlConnection connection = new SqlConnection(connectionString))
{
if (connection.State == ConnectionState.Closed)
connection.Open();

I don't think that you need to check the connection string state and open it afterwards when you are using the "using" command.
 
yah, who cares about readability and maintainability :p
 
"A"? Really now?

I think you need to clean up a lot of code once you got this working.

+1

Code is always cleaned. Weekly code reviews for all dev staff. Passed this piece of code this morning :) and we take reviews very seriously as of late :twisted:.
 
Code:
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("sp_submit", conn))
{
    conn.Open();
    cmd.CommandType = CommandType.StoredProcedure;

    var param = cmd.Parameters.AddWithValue("@myTable", table);
    param.SqlDbType = SqlDbType.Structured;

    result = cmd.ExecuteNonQuery();
}

There...do it that way and get it done with.
 
First lesson... Touch type. That way, you will anyways type readable code, and will never have the code nazi's on your back
 
Top
Sign up to the MyBroadband newsletter
X