none
error when saving in database RRS feed

  • Question

  • hi

     

    in my app i want to edit a row from a db and save it, quit easy but the Table i read contains 98 columns its an access db so normaly i think it hasn't reached it limit. but i cant save my row, i can save it when i delete a column

    any body an idea how this comes, i believe it has something to do with Ms access, but when i addjust the row in access it saves without any error.

    im quite lost in this ....

    here is my code

     

    to read form the db an create it in an datagridview

    public BindingSource createVDAdb()

    {

    string query = "SELECT * FROM Tabel1";

    string conStr = provider + path;

    adapter = new OleDbDataAdapter(query, conStr);

    cb = new OleDbCommandBuilder(adapter);

    ds = new DataSet();

    adapter.Fill(ds, "Tabel1");

    ds.Tables[0].TableName = "Tabel1";

    BS= new BindingSource(ds, "Tabel1");

    datagridview.DataSource = BS;

    return BS;

    }

     

    to save

    public void saveVDA()

    {

    DataTable tabel_Mod =

    (DataTable)ds.Tables[0].GetChanges(DataRowState.Modified);

    DataTable tabel_Add =

    (DataTable)ds.Tables[0].GetChanges(DataRowState.Added);

    DataTable tabel_Del =

    (DataTable)ds.Tables[0].GetChanges(DataRowState.Deleted);

    try

    {

    if (tabel_Mod != null)

    { adapter.Update(ds, "Tabel1"); }

    if (tabel_Add != null)

    { adapter.Update(ds, "Tabel1"); }

    if (tabel_Del != null)

    { adapter.Update(ds, "Tabel1"); }

    }

    catch

    {

    // adapter.Fill(ds, "Tabel1");

    }

    finally

    {

    if (tabel_Mod != null)

    { tabel_Mod.Dispose(); }

    if (tabel_Add != null)

    { tabel_Add.Dispose(); }

    if (tabel_Del != null)

    { tabel_Del.Dispose(); }

    }

    }

     

     

    as i said, im sure the code is correct, but there most be some limitation i dont know about

    can somebody help

    grz muk

     

    Monday, February 18, 2008 9:26 AM

Answers

  •  

    i found the solution here :

    http://support.microsoft.com/kb/194127

    its a bug in access => my select query is limited to a certain lenght and i got that lengt when i added the 98th column

    i do have the luck that i dont realy need all 98 columns so i changed my select query to what i do need so the lengt isnt to large.

    thx for the tips on the update Smile

    grz muk

    Monday, February 18, 2008 12:49 PM

All replies

  • You certainly don't need to call adpater.Update() 3 times, this may be the cause of your problem.

     

    Update will handle all additions, deletions and modifictions in a single call.

     

    You could make your save method as simple as

     

    public void saveVDA()

    {

        adapter.Update(ds, "Tabel1");

    }

     

     

     

    Monday, February 18, 2008 11:20 AM
  • Looking at it again, your code will try to add the same record three times which would break your database.

     

    It would however handle deletions and modifications without issue

    Monday, February 18, 2008 11:30 AM
  •  

    i found the solution here :

    http://support.microsoft.com/kb/194127

    its a bug in access => my select query is limited to a certain lenght and i got that lengt when i added the 98th column

    i do have the luck that i dont realy need all 98 columns so i changed my select query to what i do need so the lengt isnt to large.

    thx for the tips on the update Smile

    grz muk

    Monday, February 18, 2008 12:49 PM