Update requires a valid command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • N! Xau

    #1

    Update requires a valid command

    Hi all,

    I created a dataform using the wizard, everything works fine.
    I set both grids to readonly = true, and added a button to switch this
    property and save modifications to db. I didn't make any other changes
    to the auto-generated code.
    But I keep having an error:
    "Update requires a valid update command when passed DataRow collection
    with modified rows"

    Button's click code is:

    If bEdit.Text = "Edit" Then
    grdMaster.ReadO nly = False
    grdDetail.ReadO nly = False
    bEdit.Text = "Save"
    Else
    Try
    OleDbDataAdapte r1.Update(DSMas ter)
    OleDbDataAdapte r2.Update(DSMas ter)
    Catch ex As Exception
    MsgBox("bEdit: Update failed" & vbCrLf & ex.Message)
    End Try
    grdMaster.ReadO nly = True
    grdDetail.ReadO nly = True
    bEdit.Text = "Edit"
    End If



    thanks for help

    N! Xau

    Keep in mind the power of ANTANI


  • Bart Mermuys

    #2
    Re: Update requires a valid command

    Hi,

    "N! Xau" <nxau@hotmail.c om> wrote in message
    news:1130431278 .958223.34280@g 43g2000cwa.goog legroups.com...[color=blue]
    > Hi all,
    >
    > I created a dataform using the wizard, everything works fine.
    > I set both grids to readonly = true, and added a button to switch this
    > property and save modifications to db. I didn't make any other changes
    > to the auto-generated code.
    > But I keep having an error:
    > "Update requires a valid update command when passed DataRow collection
    >with modified rows"[/color]

    Check if you have two OleDbCommand's for update on the form and check if
    they are assigned to the OleDbDataAdapte r's (see designer generated code).

    The wizard will not create an update command for a table that doesn't have a
    primary key. It won't work with db views(joins) either.

    You can setup/refresh each OleDbDataAdapte r individually by right-clicking
    on them and select "configure dataadapter", this way it will warn you if it
    couldn't create some of the commands.


    HTH,
    Greetings
    [color=blue]
    >
    > Button's click code is:
    >
    > If bEdit.Text = "Edit" Then
    > grdMaster.ReadO nly = False
    > grdDetail.ReadO nly = False
    > bEdit.Text = "Save"
    > Else
    > Try
    > OleDbDataAdapte r1.Update(DSMas ter)
    > OleDbDataAdapte r2.Update(DSMas ter)
    > Catch ex As Exception
    > MsgBox("bEdit: Update failed" & vbCrLf & ex.Message)
    > End Try
    > grdMaster.ReadO nly = True
    > grdDetail.ReadO nly = True
    > bEdit.Text = "Edit"
    > End If
    >
    >
    >
    > thanks for help
    >
    > N! Xau
    >
    > Keep in mind the power of ANTANI
    > http://ilovemiliofede.altervista.org
    >[/color]


    Comment

    Working...