Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# with database

C# with database

Scheduled Pinned Locked Moved C#
csharpdatabasehelpquestionannouncement
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hkl
    wrote on last edited by
    #1

    Hi, I am writing a program with a database ( xxxx.mdb), and the data set is displayed on a DataGrid. I've implemented an Add function to add new record and it's ok. But I can't delete an existing record. The following code is what I've used. this.BindingContext[dbProductSet1, "Products"].RemoveAt(this.BindingContext[dbProductSet1, "Products"].Position); It runs ok, but the record can't be deleted. And, when I later execute: oleDbDataAdapter1.Update(dbProductSet1); An error occurs saying: "Update requires a valid DeleteCommand when passed DataRow collection with deleted rows." Afterward, I added this line and tried again: dbProductSet1.Products.AcceptChanges(); The error message is gone and it seems ok, but in fact the "deleted" record isn't deleted!! Can anyone please give me comments?? Thank you!!!

    H 1 Reply Last reply
    0
    • H hkl

      Hi, I am writing a program with a database ( xxxx.mdb), and the data set is displayed on a DataGrid. I've implemented an Add function to add new record and it's ok. But I can't delete an existing record. The following code is what I've used. this.BindingContext[dbProductSet1, "Products"].RemoveAt(this.BindingContext[dbProductSet1, "Products"].Position); It runs ok, but the record can't be deleted. And, when I later execute: oleDbDataAdapter1.Update(dbProductSet1); An error occurs saying: "Update requires a valid DeleteCommand when passed DataRow collection with deleted rows." Afterward, I added this line and tried again: dbProductSet1.Products.AcceptChanges(); The error message is gone and it seems ok, but in fact the "deleted" record isn't deleted!! Can anyone please give me comments?? Thank you!!!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Once you do DataSet.AcceptChanges() or DataTable.AcceptChanges(), a DataAdapter no longer sees your changes and therefore doesn't call the required command. DataAdapter() uses DataSet or DataTable.GetChanges() to get a DataSet or DataTable with just the changes and it knows (based on state) which rows have been deleted, inserted, or updated. So, as the error states, you need to assign an OleDbCommand to the DeleteCommand property of the OleDbDataAdapter. That way, when it runs across a record that has been marked for deletion, it'll call the appropriate SQL statement to delete the record. "Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups