none
Updating database through OleDBDataAdapter.Update, InsertCommand issue RRS feed

  • Question

  • Hi guys,

    I hope this is the right section to post this problem...

    I'm loading my *.mdb file into a DataTable, and a set of row of interest loaded from a *.xls file into another DataTable. Then I add the rows from this "xls" table to the DataTable which represents my mdb file. At this point I call for the OleDbDataAdapter Update method to update my mdb data source from the table, discovering that it needs the InsertCommand property to be setted. And so the problem is that I don't know how to set the sql string to perform the action. I mean, I know sql but I don't know the syntax to link the sql with the data i have to insert.

    Here's my code:

    //table -> mdb table
    //xlsTable -> excel table
    
    foreach (DataRow dr in xlsTable.Rows)
    {
    row = table.NewRow();
     for (int i=0; i<table.Columns.Count; i++)
     {
      row[i] = dr[i];
     }
     table.Rows.Add(row);
    }
    // (...) opening db connection code (...)
    try
    {
     adapter.InsertCommand = new OleDbCommand(...);
     adapter.Update(table);
    }
    catch (Exception e)
    {
     //(...)
    }
    

     I know the sql string for the InsertCommand should be something like "INSERT INTO myTable VALUES...", but I can't find in the documentation the syntax that fit my case.

    Tanks to anyone who can help setting this string!

    P.S.: I don't know if my way of doing shown in the code above it's the common way of doing, neither if it's the smartest or not... I'm just a subject beginner ;)

    Thursday, July 8, 2010 8:30 PM

Answers

All replies