update database with dataset/dataadapter RRS feed

  • Question

  • User67576075 posted


    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;


    //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["NAAM"] = "iets";
    editRow["GESLACHT"] = "M";
    editRow["STRAAT"] = "een straat";

    da.Update(ds, "Inschrijvingen");

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


  • User-1659704165 posted


    //csharp sample

    //Vb Sample

    Check the above link

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