C# SqlDataAdapter to ODBC export RRS feed

  • Frage

  • Dear Forummembers,

    I am trying to adapt a program, by transforming the output part of it, so it can export to ODBC(SAS), as previously it exported to plain text.
    Thus I create an SqlDataAdapter "da" by executing a rather complicated query( _sqlCommand) from a connection to an SQL Server(defined in _connection).
    Later I fill the table dataTable with the result from that query. That part is fine as I can see in the debug the expected result. My next step would be to "export" dataTable into an ODBC(SAS) table with the same extructure. Therefore my idea was to create another query into sbInsertCommand2, which transfers the records from "dataTable" to my target table "Baseline2"(in "Demo" directory, as used in SAS). Odviously has this construct an error(probably the [dataTable] reference) that I get when executing the last row.

    Can anybody help me on how to build that query properly?

    //***** This is your table to hold the result set:
    DataTable dataTable = new DataTable();


    //***** This is your data adapter that understands SQL databases:
    SqlDataAdapter da = new SqlDataAdapter(_sqlCommand, _connection);


    //***** Fill the data table with select statement's query results:
    //***** dataTable will be used one step later in the query executed with ExecuteScalar()

    int recordsAffected = da.Fill(dataTable);

    StringBuilder sbInsertCommand2 = new StringBuilder();
    sbInsertCommand2.Append("INSERT INTO Demo.");
    sbInsertCommand2.Append(" select * from [dataTable]");

    _insertCommand2 = new OdbcCommand(sbInsertCommand2.ToString(), _sasConnection);


    Donnerstag, 23. Oktober 2008 10:30

Alle Antworten