none
Update whole Database table without primary key from DataGridView RRS feed

  • Question

  • I have table without primary key. And while using SqlCOmmandBuilder for updating it, it gives me 
    -
    Exception: "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key ".
    I can update table with my own SqlCommand update statements like that:
    -
    SqlCommand cmd = new SqlCommand("Update Table bla bla bla..", connection);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.UpdateCOmmand = cmd;
    -
    But How can I achieve to update whole table(i mean that like SqlServer, i will edit all columns which i want, not only certain columns) without Primary key?

    Assassin's Creed: Nothing is True, Everything is Permitted.


    Friday, January 27, 2012 10:32 AM

Answers

  • why don't you set primary keys for your datatables, the adapter will always create update command by Primary key according the select T-SQL. you should manually set all updateCommand by yourself.


    I am fish.
    • Marked as answer by Ferhad Cebiyev Tuesday, January 31, 2012 12:22 PM
    Monday, January 30, 2012 9:04 AM
  • Unlike Insert , update needs a primary key for at least one of the column in your database. Otherwise, you need to create your UpdateCommand manually and assign them to the respective properties of Adopter that is why your second approach is working fine.
    Lingaraj Mishra
    • Marked as answer by Ferhad Cebiyev Tuesday, January 31, 2012 12:22 PM
    Tuesday, January 31, 2012 8:38 AM

All replies

  • why don't you set primary keys for your datatables, the adapter will always create update command by Primary key according the select T-SQL. you should manually set all updateCommand by yourself.


    I am fish.
    • Marked as answer by Ferhad Cebiyev Tuesday, January 31, 2012 12:22 PM
    Monday, January 30, 2012 9:04 AM
  • I am creating Sql Editor. This project is given me by our teacher.   

    And I want to make it work like Sql Server.  After clicking 'Edit tables' edittables tabitem is appeared. It is datagrid.It is editable. And i want that after editing to update whole table.  So i dont want to set primary key for all tables one by one.

     

     

     


    Assassin's Creed: Nothing is True, Everything is Permitted.
    Monday, January 30, 2012 7:02 PM
  • Unlike Insert , update needs a primary key for at least one of the column in your database. Otherwise, you need to create your UpdateCommand manually and assign them to the respective properties of Adopter that is why your second approach is working fine.
    Lingaraj Mishra
    • Marked as answer by Ferhad Cebiyev Tuesday, January 31, 2012 12:22 PM
    Tuesday, January 31, 2012 8:38 AM
  • ok..Thanks.
    Assassin's Creed: Nothing is True, Everything is Permitted.
    Tuesday, January 31, 2012 12:23 PM