Results 1 to 7 of 7

Thread: update database from dataset

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28

    update database from dataset

    Hi,
    I am binding a dataset to the datagrid. In the datagrid, i am editing a record. My table doesn't have primary key. I think commandbuilder doesn't work becoz of no primary key. Pls tell me how to update the database from the dataset using the dataadapter. I am using Access database.
    private sub btnupdate_click(...)
    if ds.haschanges then
    da.update(ds.tables("Customer")
    endif
    end sub
    Thanks in advance

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    it wont update if you dont have a primary key on your table..

    dataadapter seeks for the primary key.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28
    Is any other way to update the dataset into database?

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    Originally posted by KnowledgeSeeker
    Is any other way to update the dataset into database?
    Yes. and dont ask me how?


    and BTW why wont you put primary key on your table?

  5. #5
    Addicted Member
    Join Date
    Apr 2004
    Location
    Lagos, Nigeria
    Posts
    215
    You need to create sql commands for the dataadapter.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28
    can u give me example? My dataset may contains around 5 records which are added or edited records, how to store it in database using dataadapter.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    28
    I have 2 tables "Child" and "Relations"
    In table "Child",
    Roll_No Child_Name Class
    ===== ======== ====
    1000 John I
    1001 David II

    In table "Relations",
    Parent_Name Roll_No Role
    ========== ====== ====
    Robinson 1000 Father
    Paul 1001 Father
    Jennifer 1001 Mother
    Paul 1000 Carer

    I am showing the "relations" table records of Roll_No = 1000 in datagrid using dataset, so it will show Robinson & Paul Records. Suppose if i am modifying the role of Paul to "Grand Parent" from "Carer" and try to update, it will given an error because, i don't have Primary Key in my table. Will it work if I add Auto Increment (PK) field?

    I am thinking of doing it in this way. before updating the dataset into the database, first deleting the Records having Roll_No = 1000 in "relations" table and then adding into "Relations" table with modified dataset using dataadapter. Is it the correct way?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width