locked
update database with dataset/dataadapter RRS feed

  • Question

  • User67576075 posted

     hi,

    i want to update my database using a dataset/dataadapter

    everything seems to work fine and all my changes are added to my dataset but when i want to add my dataset to my database the database isn't updated

    private void UpdateTable()
    {
    OleDbConnection conn = null;
    OleDbDataAdapter da = null;
    DataSet ds = null;

    try
    {

    //ophalen van de connectiestring
    string connString = ConfigurationManager.ConnectionStrings["ExamenproefConnectionString"].ToString();
    conn = new OleDbConnection(connString);


    //aanmaken van de dataAdapter
    da = new OleDbDataAdapter();

    //aanmaken vh selectiecommando
    string sql = "SELECT * FROM tblInschrijvingen ORDER BY NAAM;";
    OleDbCommand cmd = new OleDbCommand(sql, conn);
    da.SelectCommand = cmd;


    //aanmaken van updatecommando
    sql = "UPDATE tblInschrijvingen SET naam=?, geslacht=?, straat=? WHERE id=?";
    cmd = new OleDbCommand(sql, conn);



    cmd.Parameters.Add("?", OleDbType.VarWChar, 50, "NAAM");
    cmd.Parameters.Add("?", OleDbType.VarWChar, 1, "GESLACHT");
    cmd.Parameters.Add("?", OleDbType.VarWChar, 30, "STRAAT");
    cmd.Parameters.Add("?", OleDbType.Integer, 3, "ID");


    da.UpdateCommand = cmd;


    ds = new DataSet();

    da.Fill(ds, "Inschrijvingen");


    GridViewRow row = gv.SelectedRow;
    iGeselecteerd = row.DataItemIndex;


    DataTable table = ds.Tables["Inschrijvingen"];
    DataRow editRow = table.Rows[iGeselecteerd];
    editRow.BeginEdit();
    editRow["NAAM"] = "iets";
    editRow["GESLACHT"] = "M";
    editRow["STRAAT"] = "een straat";
    editRow.EndEdit();





    ds.AcceptChanges();
    da.Update(ds, "Inschrijvingen");
    BindGrid();



    }
    catch (Exception ex)
    {
    lblError.Text = ex.Message;
    }
    }
    Sunday, May 24, 2009 11:48 AM

Answers

  • User-1659704165 posted

     Hi,

    //csharp sample
    http://support.microsoft.com/kb/308507

    //Vb Sample
    http://support.microsoft.com/kb/301248

    Check the above link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2009 1:01 AM