locked
Edit a non-empty row RRS feed

  • Question

  •  

    Hi everyone!

     

    I need a help from you!

     

    I've got a dataset in my project: 4 grids and 4 nav bars.

    Every time i edit a row, i save it. But when i restart the program and i would to edit that row again, when I click on the button 'save' Visual Studio shows me an error message: Update request a valid UpdateCommand...

     

    How to resolve it?

     

    Last question: how to activate in the nav bar 'add row' and 'delete row' button? I double-click on it but doesn't appear the code to do that actions.

     

    Thanks a lot!

     

    FV

    Friday, October 5, 2007 6:46 AM

Answers

  • You are missing the WHERE condition.

     

    UPDATE Table_Name

    SET [Velocita] = ?, [Cognome]=?

    WHERE [pkey_column] = ?

     

     

    [pkey_column] identifies you primary key column. Otherwise the update statement will affect all rows in you table.

     

     

    Regards,

    franking

    Tuesday, October 9, 2007 2:41 PM
  • that's quite the same.

     

    In the tableadapter properties window, add a new query for DeleteCommand.

    Set the query to something like

     

    DELETE FROM Table_name

    WHERE [pkey_column] = ?

     

     

    This should be all you need. But be careful with delete commands Wink

     

    Hope this helps,

    franking

    Wednesday, October 10, 2007 9:24 AM

All replies

  • Hi,

     

    check your dataset again. If you're able to insert a new record, your tableadapter contains a valid insert command.

    It seems like you haven't defined an update command for the same tableadapter and this is why the exception is thrown. Open the designer, and examine your tableadapters.

     

    I'm not clear about your second question, but I assume you're talking about a BindingNavigator?! Do you have a BindingSource instance assigned to this control?

     

    First of all, those ToolStripButtons objects are components and no controls, so you have to expect a different behavior. However, they also provide the Click and DoubleClick events and they trigger the assigned BindingSource automatically. If nothing happens on clicking, something's wrong with your binding source.

     

    Hope this helps,

    franking

     

     

    Friday, October 5, 2007 7:19 AM
  • When i double click (in Designer) on 'Save Button' program automatically shows me this code:

     

    this.Validate();

    this.GRID_NAMEBindingSource.EndEdit();

    this.GRID_NAMETableAdapter(this.Databaseset.GRID_NAME);

     

    and when I click on it everything is saved.

    But when i double click (in Designer) on '+' or 'x' button, program creates me an empty function...

    What I've to write in ToolStrip_Button to associate '+' symbol to add a row and 'x' symbol to delete a row?

     

    Thanks!

     

    Last thing: i can't understand how to edit tableadapter to edit a non empty row...could you help me?

     

    Thanks a lot...really a lot!

     

    Monday, October 8, 2007 1:35 PM
  • BindingNavigator was designed to work with BindingSource as data source.

     

    Code Block

    ...

    this.navOrders.DataSource = this.srcOrdersBindingSource;

    ...

     

    In this case, the Add and Remove buttons should work without custom event handling.

    If you don't use a BindingSource instance as data source, then you can insert a new row to the data table directly.

     

    Code Block

    ...

    DataRow row = this.tblCustomers.NewRow();

    // do something to fill the new row

    this.tblCustomers.Rows.Add(row);

    ...

     

    Your tableadapter will try to add the new row to the database when Update() is invoked.

     

    If you want to edit a non-empty row, you have to specify an UpdateCommand for the tableadapter. If you open the dataset, the designer shows all table definitions inside the dataset. You should also see the tableadapter inside the displayed box for each table. Open the properties window and set a new command for UpdateCommand.

     

    If you can't find a tableadapter inside you table definition, you have to add one.

     

    Hope this helps,

    franking

    Monday, October 8, 2007 2:35 PM
  • I can see the TableAdapter for each table...but i've got only SELECT and INSERT command...

     

    I double-click on Update and it generate automatically an UpdateCommand, but empty!!

    I wrote an SQL command like this:

     

    UPDATE Table_Name

    SET [Velocita] = ?, [Cognome]=?

     

    but when i try to update a non empty row with new values, it duplicates those new values for each row...

     

    Please, write me UpdateCommand only for a modified row...

     

    thanks a lot...really a lot!

     

     

     

     

    Tuesday, October 9, 2007 2:19 PM
  • You are missing the WHERE condition.

     

    UPDATE Table_Name

    SET [Velocita] = ?, [Cognome]=?

    WHERE [pkey_column] = ?

     

     

    [pkey_column] identifies you primary key column. Otherwise the update statement will affect all rows in you table.

     

     

    Regards,

    franking

    Tuesday, October 9, 2007 2:41 PM
  • GREAT!

     

    Thanks a lot!

     

    But i've the same problem with Delete property: i double-click on 'x' button and it generates me the function...but nothing happen!

    I've to write a query there too? And how?

     

    PS: i'll offer a huge pizza if u'll come in Italy...u'll be my guest if u can resolve that problem!

     

    Wink

    Wednesday, October 10, 2007 8:05 AM
  • that's quite the same.

     

    In the tableadapter properties window, add a new query for DeleteCommand.

    Set the query to something like

     

    DELETE FROM Table_name

    WHERE [pkey_column] = ?

     

     

    This should be all you need. But be careful with delete commands Wink

     

    Hope this helps,

    franking

    Wednesday, October 10, 2007 9:24 AM