DataAdapter/Update problem

E

Elmo

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

S. Justin Gengo

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
 
E

Elmo

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top