DataAdapter/Update problem

Discussion in 'ASP .Net' started by Elmo, Nov 8, 2003.

  1. Elmo

    Elmo Guest

    I've got a situation where I'm trying to fix an existing table - - The Fname
    Field has both First & Last Names...

    So - I've populated a Dataset with the ID, First and Last names - - -

    I'm iterating through the datatable, Fixing the datat and assigning the
    First and Last name to variables, which I then, want to use to update the
    first and last name fields with.

    I keep getting an error when I try to do the Update on the row:
    "Update requires a valid UpdateCommand when passed DataRow collection with
    modified rows. "

    So far, here's what I've got :
    For Each MyRow in ds.Tables(0).Rows
    'Manipulate the data here - - asign First to sFirst and Last to sLast
    variables (working perfectly)
    'I then populate the update command:
    UpDateSQL="Update Registered set Fname = '" & sFirst & "', Lname='" & sLast
    & "' where ID = " & iID
    Dim upDateCmd as New SqlCommand(UpdateSQL, MyConn)
    UpdateCmd.CommandText=UpDateSQL
    Trace.Warn ("commandText = " & UpdateCmd.CommandText) <---- this shows up
    perfectly - exactly what is needed to update the table

    da.Update(ds, "Registered") <-- error occurs here

    What's wrong here?

    Apparently I'm missing something, but I don't have the slightest idea what
    it is.
    Elmo, Nov 8, 2003
    #1
    1. Advertising

  2. Elmo,

    Skip all the code and just modify your SQL instead.

    SELECT (LastName + ", " + FirstName) AS FullName FROM tblNames

    With the code above your database will return a column "FullName" to the
    dataset and you're done.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Elmo" <> wrote in message
    news:...
    > I've got a situation where I'm trying to fix an existing table - - The

    Fname
    > Field has both First & Last Names...
    >
    > So - I've populated a Dataset with the ID, First and Last names - - -
    >
    > I'm iterating through the datatable, Fixing the datat and assigning the
    > First and Last name to variables, which I then, want to use to update the
    > first and last name fields with.
    >
    > I keep getting an error when I try to do the Update on the row:
    > "Update requires a valid UpdateCommand when passed DataRow collection with
    > modified rows. "
    >
    > So far, here's what I've got :
    > For Each MyRow in ds.Tables(0).Rows
    > 'Manipulate the data here - - asign First to sFirst and Last to sLast
    > variables (working perfectly)
    > 'I then populate the update command:
    > UpDateSQL="Update Registered set Fname = '" & sFirst & "', Lname='" &

    sLast
    > & "' where ID = " & iID
    > Dim upDateCmd as New SqlCommand(UpdateSQL, MyConn)
    > UpdateCmd.CommandText=UpDateSQL
    > Trace.Warn ("commandText = " & UpdateCmd.CommandText) <---- this shows up
    > perfectly - exactly what is needed to update the table
    >
    > da.Update(ds, "Registered") <-- error occurs here
    >
    > What's wrong here?
    >
    > Apparently I'm missing something, but I don't have the slightest idea what
    > it is.
    >
    >
    >
    S. Justin Gengo, Nov 8, 2003
    #2
    1. Advertising

  3. Elmo

    Elmo Guest

    Sorry - it's just the opposite I need - -
    The full name is actually in the Fname field (I know - don't ask why - that
    was before me) - - now
    I'm trying to split that up into the first & last name fields.


    "S. Justin Gengo" <> wrote in message
    news:%232c%...
    > Elmo,
    >
    > Skip all the code and just modify your SQL instead.
    >
    > SELECT (LastName + ", " + FirstName) AS FullName FROM tblNames
    >
    > With the code above your database will return a column "FullName" to the
    > dataset and you're done.
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Elmo" <> wrote in message
    > news:...
    > > I've got a situation where I'm trying to fix an existing table - - The

    > Fname
    > > Field has both First & Last Names...
    > >
    > > So - I've populated a Dataset with the ID, First and Last names - - -
    > >
    > > I'm iterating through the datatable, Fixing the datat and assigning the
    > > First and Last name to variables, which I then, want to use to update

    the
    > > first and last name fields with.
    > >
    > > I keep getting an error when I try to do the Update on the row:
    > > "Update requires a valid UpdateCommand when passed DataRow collection

    with
    > > modified rows. "
    > >
    > > So far, here's what I've got :
    > > For Each MyRow in ds.Tables(0).Rows
    > > 'Manipulate the data here - - asign First to sFirst and Last to sLast
    > > variables (working perfectly)
    > > 'I then populate the update command:
    > > UpDateSQL="Update Registered set Fname = '" & sFirst & "', Lname='" &

    > sLast
    > > & "' where ID = " & iID
    > > Dim upDateCmd as New SqlCommand(UpdateSQL, MyConn)
    > > UpdateCmd.CommandText=UpDateSQL
    > > Trace.Warn ("commandText = " & UpdateCmd.CommandText) <---- this shows

    up
    > > perfectly - exactly what is needed to update the table
    > >
    > > da.Update(ds, "Registered") <-- error occurs here
    > >
    > > What's wrong here?
    > >
    > > Apparently I'm missing something, but I don't have the slightest idea

    what
    > > it is.
    > >
    > >
    > >

    >
    >
    Elmo, Nov 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Galen Harris

    dataadapter.update -- dataset from session

    Galen Harris, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    534
    Jacob Yang [MSFT]
    Oct 24, 2003
  2. Galen Harris
    Replies:
    1
    Views:
    458
    Patrik Löwendahl
    Oct 24, 2003
  3. Guest

    DataAdapter and Update method

    Guest, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    Guest
    Dec 2, 2003
  4. Janaka

    DataAdapter update

    Janaka, Sep 13, 2004, in forum: ASP .Net
    Replies:
    20
    Views:
    2,452
    Girish Bharadwaj
    Sep 13, 2004
  5. Big Dave
    Replies:
    1
    Views:
    558
    Michael O'Brien
    Oct 1, 2004
Loading...

Share This Page