Results 1 to 4 of 4

Thread: Update requires valid UpdateCommand

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Update requires valid UpdateCommand

    I see this error

    Update requires valid UpdateCommand passed DataRow collection modified rows.

    When I run the following code. But the strange thing is that I have similar code on another form and it works great. The only difference is the database table is different. I verified both tables and they look identical, as far as settings. I have verified that _Non_MS_Office_Licenses has a primary key that is unique. Looking in dataset manager I see the query for fillBy() is fine and it has all the insert and update stuff. At the end when it verifies it says all is verified when I configure the dataset

    Code:
     Dim row = FrmApp.Non_MS_Office_LicensesBindingSource.Current
    
                        row("Primary User") = Replace(CStr(TxtUserid.Text), "'", "`")
                        row("Staff Last Name") = Replace(CStr(TxtLastName.Text), "'", "`")
                        row("Staff First Name") = Replace(CStr(TxtFirstName.Text), "'", "`")
                        row("CI Name") = Replace(CStr(TxtTitle.Text), "'", "`")
                        row("Version") = Replace(CStr(TxtVersion.Text), "'", "`")
                        row("New/Upgrade") = Replace(CStr(CmboNewUgd.SelectedItem), "'", "`")
                        row("PO Number") = Replace(CStr(TxtPONumber.Text), "'", "`")
                        row("PCard") = CBool(PCard)
                        row("Company") = Replace(CStr(TxtSoftwareCo.Text), "'", "`")
                        row("Invoice Date") = Replace(CStr(TxtInvDate.Text), "'", "`")
    
                        row("Invoice Number") = Replace(CStr(TxtInvNumber.Text), "'", "`")
                        row("Serial/License/Keycode") = Replace(CStr(TxtSerial.Text), "'", "`")
                        row("Department") = Replace(CStr(CmbDept.SelectedItem), "'", "`")
                        row("Server") = CStr(CmboServer.SelectedItem)
                        row("Assigned Date") = Replace(CDate(TxtAssignedDate.Text), "'", "`")
    
                        If TxtComment.Text.Length > 1 Then
                            row("Working Notes") = Replace(CStr(TxtComment.Text), "'", "`")
                        Else
                            row("Working Notes") = DBNull.Value
                        End If
    
                        row("Type of License") = CStr(CmboLicType.SelectedItem)
                        row("CI Subtype") = CStr(CmboSubType.SelectedItem)
                        row("Division") = Replace(CStr(TxtDivision.Text), "'", "`")
                        ' row("CI Type") = "Software Application"
    
                       
    
                        FrmApp.Non_MS_Office_LicensesBindingSource.EndEdit()
                        intTotalChanges = FrmApp.Non_MS_Office_LicensesTableAdapter.Update(FrmApp.SoftwareDataSet._Non_MS_Office_Licenses)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Update requires valid UpdateCommand

    If your TableAdapter hasn't had an UpdateCommand generated automatically and it was generated from a database table then that table mustn't have a primary key. The PK is used to uniquely identify each record so, if there's no PK, the adapter can't identify which record to update so it leaves it up to you to write the UpdateCommand yourself. It's really quite a rare thing for a database table to justifiably not have a primary key though, so the better option would be to add one and then regenerate your TableAdapter.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: Update requires valid UpdateCommand

    Thanks jmcilhinney,

    I suspected that as well. But when I first started this project I had one and some place along the lines I ended up with 3. So I reconfigured my database, reconfigured my DataSet, deleted the tableadapter and re added the binding but it always saw the old stuff. Even though the DataSet had the correct primary key the datagridview was still loading the old dataset. So I deleted the grid and reloaded and re-bound the table and it still showed the old stuff. It wasn't until I added a new dataset is when it started to work correctly. But now it shows I have like 10 datasets when I preview the data from the dataset. Is there a cache some place?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Update requires valid UpdateCommand

    You're going to have to use more precise terminology because I doubt that you have 10 DataSets and, even if you do, all you have to do is delete them. You must have 10 of something else but I don't know what. The simple fact is, barring system corruption of some sort, if you specify the correct database when creating your Data Source then your DataSet will have the right schema. I can only assume that you are specifying the wrong database. Maybe you're changing the schema of an original MDB or ACCDB file instead of the one in your project or something like that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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