delete multiple rows from table doesnt contain primary key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?S2F5xLFoYW4=?=

    delete multiple rows from table doesnt contain primary key

    In my project,i added datagridview to my form , i transfered my table to
    datagridview and added multiple rows and when i called dataadapther.up date
    ,,result is ok. But when i tried it for the delete operations,i got the
    error like "set primary key in your table" ,,i want delete multiple rows from
    Datatable which doesnt contain primary key
  • Peter Bromberg [C# MVP]

    #2
    Re: delete multiple rows from table doesnt contain primary key

    If your table doesn't have a primary key, then you'll need to supply a WHERE
    clause that is distinct enough to disambiguate which rows to delete.
    Peter

    "Kayıhan" <Kayhan@discuss ions.microsoft. comwrote in message
    news:A0103CCC-9627-4DD1-A874-D132D3F8E947@mi crosoft.com...
    In my project,i added datagridview to my form , i transfered my table to
    datagridview and added multiple rows and when i called
    dataadapther.up date
    ,,result is ok. But when i tried it for the delete operations,i got the
    error like "set primary key in your table" ,,i want delete multiple rows
    from
    Datatable which doesnt contain primary key

    Comment

    • =?Utf-8?B?S2F5xLFoYW4=?=

      #3
      Re: delete multiple rows from table doesnt contain primary key

      instead of supply where clause, i prefer choose row from table and delete it
      with
      "row.Delete (); dataAdapther.Up date(table);" . idont understand why i am not
      allowed; what is the harm about it? why primary key is needed for delete but
      not for insert or update operations?
      thanks

      "Peter Bromberg [C# MVP]" wrote:
      If your table doesn't have a primary key, then you'll need to supply a WHERE
      clause that is distinct enough to disambiguate which rows to delete.
      Peter
      >
      "Kayıhan" <Kayhan@discuss ions.microsoft. comwrote in message
      news:A0103CCC-9627-4DD1-A874-D132D3F8E947@mi crosoft.com...
      In my project,i added datagridview to my form , i transfered my table to
      datagridview and added multiple rows and when i called
      dataadapther.up date
      ,,result is ok. But when i tried it for the delete operations,i got the
      error like "set primary key in your table" ,,i want delete multiple rows
      from
      Datatable which doesnt contain primary key
      >

      Comment

      • =?UTF-8?B?TGFzc2UgVsOlZ3PDpnRoZXIgS2FybHNlbg==?=

        #4
        Re: delete multiple rows from table doesnt contain primary key

        Kayıhan wrote:
        instead of supply where clause, i prefer choose row from table and delete it
        with
        "row.Delete (); dataAdapther.Up date(table);" . idont understand why i am not
        allowed; what is the harm about it? why primary key is needed for delete but
        not for insert or update operations?
        thanks
        >
        "Peter Bromberg [C# MVP]" wrote:
        >
        >If your table doesn't have a primary key, then you'll need to supply a WHERE
        >clause that is distinct enough to disambiguate which rows to delete.
        >Peter
        >>
        >"Kayıhan" <Kayhan@discuss ions.microsoft. comwrote in message
        >news:A0103CC C-9627-4DD1-A874-D132D3F8E947@mi crosoft.com...
        >>In my project,i added datagridview to my form , i transfered my table to
        >>datagridvie w and added multiple rows and when i called
        >>dataadapther. update
        >>,,result is ok. But when i tried it for the delete operations,i got the
        >>error like "set primary key in your table" ,,i want delete multiple rows
        >>from
        >>Datatable which doesnt contain primary key
        What if you have multiple rows with the same data? I know you can simply
        say "I know I don't", but .NET can't *know* that, and it requires
        something to uniquely identify the rows to delete.

        On a different note, every table should have a primary key or you'll
        most likely have problems with it later on, like duplicate data.

        --
        Lasse Vågsæther Karlsen
        mailto:lasse@vk arlsen.no
        Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

        PGP KeyID: 0xBCDEA2E3

        Comment

        Working...