Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Datagridview update error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [RESOLVED] [2005] Datagridview update error

    I am using the following update command in the button click event:

    Code:
     ElseIf TypeOf Me.ActiveMdiChild Is WkPayment Then
                Dim ChildForm As WkPayment = DirectCast(Me.ActiveMdiChild, WkPayment)
    
                ChildForm.Validate()
                ChildForm.EMPDRAWBindingSource.EndEdit()
                ChildForm.EMPDRAWTableAdapter.Update(ChildForm.EmPaY.EMPDRAW)
                MsgBox("        Update successful       ")
    and i am getting the following error:

    Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
    What could possibly be wrong ?
    Last edited by LuxCoder; Sep 24th, 2007 at 06:17 AM.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Datagridview update error

    It's telling you exactly what you need to do: you need to provide the update commandtext for your table adapter.

  3. #3
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Datagridview update error

    I agree with stanav. Can you provide the code to setup your Table Adapter? There is probably a SelectCommand property without an UpdateCommand property.
    My.Settings.Signature = String.Empty

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

    Re: [2005] Datagridview update error

    If your TableAdapter has no UpdateCommand then either your query does not return a primary key or it contains join. Either way the wizard cannot generate an UpdateCommand automatically.

    How did you create this TableAdapter? Does it correspond directly to a table in your database? If so then that table must not have a primary key. How can you update a record if you can't uniquely identify it? How can you uniquely identify a record without a primary key?

    If you created the query yourself then you must either have not included the table's primary key or else the query references more than one table. In that case you will have to create the UpdateCommand yourself because the wizard can't do it.
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Datagridview update error

    Now that i have to set primary key, how should i do it? From the Dataset designer or should i create the same table again with the primary key in the database?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Datagridview update error

    Okies, issue resolved ! Have created new table with the primary key ! Thanks.

  7. #7
    Lively Member
    Join Date
    Mar 2009
    Posts
    90

    Re: [RESOLVED] [2005] Datagridview update error

    I need to know how to do this as well. Lux can you please provide the code? What do I put for Update and Delete commandtext ?

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