CRUD Example with Dataset, DataRow and Access Mdb RRS feed

  • Question

  • I've created (using a wizzard, don't remember which) a dataset that points to a mdb file (Access 2007)
    The generated DataSet is named "EstacionarDataSet"

    Here's some code I have:

    EstacionarDataSet ed = new EstacionarDataSet();
    DataRow newRow = ed.Tables[0].NewRow();
    newRow["patente"] = tb_Patente.Text;
    newRow["numerobox"] = tb_Box.Text;
    newRow["fechahora_ingreso"] = DateTime.Now;
    * The above code is executed in SecondForm (not mainform). I'm trying to insert a new record into the only table mdb file has (this code doesn't work, but doesn't give any exception).

    * The mainform contains a System.Windows.Forms.DataGridView component, attached to this mdb file, which works fine, it shows the records correctly, etc. (PS: I added some sample records using Access)

    * I guess the wizzard has created all the necessary code, connectionstring, etc. Project source code is available here

    * I'm needing some code samples for adding a new row, updating, and deleting... Thanks
    Beza - Custom Joomla Templates
    Friday, November 13, 2009 11:51 AM


All replies

  • It is really hard, if not impossible, to give code examples. It depends on many factors and what you want to achive.
    I would recommend to start here, this will contain lots of information on how to create, fill, update etc. when working with DataSets.

     "Using DataSets in ADO.NET"

    This posting is provided "AS IS" with no warranties.
    • Marked as answer by Yichun_Feng Thursday, November 19, 2009 4:29 AM
    • Unmarked as answer by Enrique HTC S710 Thursday, November 19, 2009 12:29 PM
    Friday, November 13, 2009 12:34 PM
  • Thanks
    I'll check the link provided...
    Beza - Custom Joomla Templates
    Friday, November 13, 2009 7:06 PM

  • The links below will show you how to use ADO.NET with access Database. especially Insert, Update Delete

    Part One

    Part Two

    Part Three
    • Marked as answer by Yichun_Feng Thursday, November 19, 2009 4:29 AM
    Friday, November 13, 2009 7:22 PM
  • Hi John
    The tutorials are great, but I'm not using OleDb
    I've generated the project using Visual Studio 2008, and the IDE generated automatically all the code, etc.
    I see the project requires the following libraries(?):


    Also, I can set DataGridView's DataSource property at designTime. The value is "myMDBTableName BindingSource"

    I've been doing research, and found that this piece of code works great when doing an update to a record contained in the DataGridView

    int nCurrentRow = dataGridView1.CurrentCellAddress.Y;
    DataRow dr;
    dr = estacionarDataSet.Estacionamiento.Rows[nCurrentRow];
    DateTime fechaEgreso = DateTime.Now;
    dr["fechahora_egreso"] = fechaEgreso;
    dr["importe"] = duracion.TotalHours * Int32.Parse(tb_PrecioHora.Text);

    Now, I only have to find out some code for deleting a record from the table/grid... I'll post in case I find it
    Itexa Custom Web Applications
    Thursday, November 19, 2009 1:01 PM
  • if your datagridview is bound to the datatable, when you perform delete on the datagridview it will delete the record automatically in the datatable.

    All you need next is to send back your deletion to the database.

    Thursday, November 19, 2009 2:37 PM