Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to insert a new row to MDB file [modified]

How to insert a new row to MDB file [modified]

Scheduled Pinned Locked Moved C#
tutorialquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Admin887
    wrote on last edited by
    #1

    First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:

    string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;

    string commandString = "Select id,Event from Events";

    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
    DataSet ds = new DataSet();
    dataAdapter.Fill(ds, "Events");

    DataTable datatable = ds.Tables[0];
    DataRow newRow = datatable.NewRow();
    newRow["id"] = "aaa";
    newRow["Event"] = "bbb";

    datatable.Rows.Add(newRow);

    dataAdapter.Update(ds, "Events");
    ds.AcceptChanges();
    Application.DoEvents();

    i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.

    modified on Thursday, July 31, 2008 3:59 AM

    L R 2 Replies Last reply
    0
    • A Admin887

      First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:

      string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;

      string commandString = "Select id,Event from Events";

      OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
      DataSet ds = new DataSet();
      dataAdapter.Fill(ds, "Events");

      DataTable datatable = ds.Tables[0];
      DataRow newRow = datatable.NewRow();
      newRow["id"] = "aaa";
      newRow["Event"] = "bbb";

      datatable.Rows.Add(newRow);

      dataAdapter.Update(ds, "Events");
      ds.AcceptChanges();
      Application.DoEvents();

      i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.

      modified on Thursday, July 31, 2008 3:59 AM

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Admin887 wrote:

      i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where?

      You need to provide an insert command. Read some of the documentation to understand how it works.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      1 Reply Last reply
      0
      • A Admin887

        First of all, i wrote execly the same Subject yesterday but i didnt understand the answer.. :( i want to add a new row to specific MDB file... my code is:

        string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;

        string commandString = "Select id,Event from Events";

        OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
        DataSet ds = new DataSet();
        dataAdapter.Fill(ds, "Events");

        DataTable datatable = ds.Tables[0];
        DataRow newRow = datatable.NewRow();
        newRow["id"] = "aaa";
        newRow["Event"] = "bbb";

        datatable.Rows.Add(newRow);

        dataAdapter.Update(ds, "Events");
        ds.AcceptChanges();
        Application.DoEvents();

        i did this code but it pop a exception: "Update requires a valid InsertCommand when passed DataRow collection with new rows" What i need t do? and where? thank you very Much G.

        modified on Thursday, July 31, 2008 3:59 AM

        R Offline
        R Offline
        rah_sin
        wrote on last edited by
        #3

        check that u have written the dataadapters insert command properly with correct parameters

        rahul

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups