none
Updating data on the SQL server RRS feed

  • Question

  • I have a table with only 1 record - data filled in directly on the SQL-server.

     

    I have made a form in C#, made me a datasource, change the datasource to DETAIL, and drag this datasource to the form and all the fields is automatically set up !

     

    When I run the form, the data is shown, but if I change some data and try to save the changes this exception comes up in the UpdateAll-line:

     

    System.InvalidOperationException was unhandled
      Message="Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
      Source="EstiMate_New"

     

    Code Snippet

    private void vIRKSOMHEDSOPLYSNINGERBindingNavigatorSaveItem_Click(object sender, EventArgs e)

    {

    this.Validate();

    this.vIRKSOMHEDSOPLYSNINGERBindingSource.EndEdit();

    this.tableAdapterManager.UpdateAll(this.estiMate_2_DevelopmentDataSet);

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    // TODO: This line of code loads data into the 'estiMate_2_DevelopmentDataSet.VIRKSOMHEDSOPLYSNINGER' table. You can move, or remove it, as needed.

    this.vIRKSOMHEDSOPLYSNINGERTableAdapter.Fill(this.estiMate_2_DevelopmentDataSet.VIRKSOMHEDSOPLYSNINGER);

    }

     

     

    I have NOT changed any code att all !

     

    What have I done wrong then ?

     

    Best regards

     

    Friday, October 24, 2008 12:38 PM

All replies

  • In my experience that has always worked in the designer.  I'd try deleting the visual and non-visual on-screen controls (everything including BindingSources, DataSets, TableAdapters, etc.) and drag the detailed components back onto your form.  See if the auto creation works the second time.  It sounds like the update command was not created properly the 1st time, maybe it will the 2nd.  If that doesn't work, I've sometimes had success in deleting my DataSet xsd file and recreating the DataSet.  It seems to be quite pluggable/unpluggable unless you've done something like created custom TableAdapters.

    Held og lykke
    Tuesday, October 28, 2008 5:42 PM
  • I think there IS an error here !

     

    If I start all over again and do NOT change anything at all - the same exception comes up:

     

    Update requires a valid UpdateCommand when passed DataRow collection with modified rows

     

    It looks like dragging "Details" to the form will NOT work - right ?

     

    Thursday, October 30, 2008 2:44 PM
  • I have tried on another machine and another SQL-server in another DB and here I can just Drag&Drop the datasource (in detail version) to a form and without any coding at all I can update, add and delete !

     

    What is wrong with my own machine or SQL-server or database ... or VS2008 ?

     

    Tuesday, November 4, 2008 9:13 AM
  • No one got any ideas to solve this ?

     

    Wednesday, November 5, 2008 9:51 AM
  • I now did a delete of all I could find from the old project and started all over again .... and now it works !

     

    I wonder what did go wrong !

     

    BUT still there is a problem ...

     

    I now have a form with the fields in "detail" layout - every field has a label and a textbox and it works fine ... in the first place because...

     

    In fact I have this problem in many other projects too and the problem is:

     

    If I change the data in a field on my form I HAVE TO change to the prev/next record for the property HasChanges to change to true.

     

    In my specific case I only have ONE record in my table - so I can't change record !

     

    Why has the HasChanges property this "disability" ?

    Friday, November 7, 2008 10:13 AM