470,594 Members | 1,105 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

update dataset and database

Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I build
that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") = "KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name WHERE
id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70, "latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item", SqlDbType.Int,
4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?
Nov 21 '05 #1
7 3231
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no changes
present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your getchanges
line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass to
the adapter (in bandwidth restricted scenarios - this can be a great boost
to performance instead of passing a whole dataset which has many rows that
haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?

Nov 21 '05 #2
how do I update the dataset.....

lets say I want to set the latin_name to the value of latinName.text when
the user click the save button. then I want to update the database...
"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Ou****************@TK2MSFTNGP12.phx.gbl...
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your
getchanges line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass
to the adapter (in bandwidth restricted scenarios - this can be a great
boost to performance instead of passing a whole dataset which has many
rows that haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?


Nov 21 '05 #3
I get this error

"Additional information: Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."

when I try this code.
System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no changes
present so any updates won't do anything")

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") = "KJHKJHJKHKJ"

If dstPlant.HasChanges() Then

Dim ds2 = dstPlant.GetChanges()

dadPlant.Update(ds2, "plant")

End If

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Ou****************@TK2MSFTNGP12.phx.gbl...
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your
getchanges line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass
to the adapter (in bandwidth restricted scenarios - this can be a great
boost to performance instead of passing a whole dataset which has many
rows that haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?


Nov 21 '05 #4
Have you specified an Insert/Delete and Update command for the dataadapter?
If not, that's the problem. The easiest way to do this is run through the
dataadapter configuration wizard (for right now - I'd not use this once I
was familiar with the way adapters work) and it will generate them for you.
You can just use a new adapter and use it, or copy it's syntax - you'll need
to create the command with paramaters and map those fields to columns - (or
you can roll your own logic but if you're new to this, it's a lot more
complex ) which the adapter does for you.
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
I get this error

"Additional information: Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."

when I try this code.
System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") = "KJHKJHJKHKJ"

If dstPlant.HasChanges() Then

Dim ds2 = dstPlant.GetChanges()

dadPlant.Update(ds2, "plant")

End If

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Ou****************@TK2MSFTNGP12.phx.gbl...
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your
getchanges line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass
to the adapter (in bandwidth restricted scenarios - this can be a great
boost to performance instead of passing a whole dataset which has many
rows that haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?



Nov 21 '05 #5
BTW, on the Debug.Assert line - it's not failing? YOu're not getting a big
obnoxious message box saying "There are no changes present"? If not,this is
a good sign b/c that means there are changes that can be submitted to the
db.. THe way the adapter works is that it loops through each row, checking
the rowstates. If they are modified, deleted, added etc, then it will look
to the corresponding command in the adapter (which in this case appears not
to exist, that's why you're getting the error you ware) and fire that
command for the row.

For right now, you're best bet is to use a CommandBuilder (which is lame but
works in a pinch and is easy to use ) or use the Configuratino wizard.

Check out http://www.betav.com -> Articles -> MSDN - Weaning developers from
the commandBuilder which discusses update scenarios in depth.
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
I get this error

"Additional information: Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."

when I try this code.
System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") = "KJHKJHJKHKJ"

If dstPlant.HasChanges() Then

Dim ds2 = dstPlant.GetChanges()

dadPlant.Update(ds2, "plant")

End If

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Ou****************@TK2MSFTNGP12.phx.gbl...
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your
getchanges line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass
to the adapter (in bandwidth restricted scenarios - this can be a great
boost to performance instead of passing a whole dataset which has many
rows that haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?



Nov 21 '05 #6
Jean,

In addition to Bill.
If you use a binded column to a textbox than the column will pushed in the
datatable by a rowchange.

If there is no rowschange than you can force that with.

BindingContext(mydatasource).endcurrentedit

I hope this helps,

Cor
Nov 21 '05 #7
thank a lot dude!
"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:OJ*************@TK2MSFTNGP15.phx.gbl...
BTW, on the Debug.Assert line - it's not failing? YOu're not getting a
big obnoxious message box saying "There are no changes present"? If
not,this is a good sign b/c that means there are changes that can be
submitted to the db.. THe way the adapter works is that it loops through
each row, checking the rowstates. If they are modified, deleted, added
etc, then it will look to the corresponding command in the adapter (which
in this case appears not to exist, that's why you're getting the error you
ware) and fire that command for the row.

For right now, you're best bet is to use a CommandBuilder (which is lame
but works in a pinch and is easy to use ) or use the Configuratino wizard.

Check out http://www.betav.com -> Articles -> MSDN - Weaning developers
from the commandBuilder which discusses update scenarios in depth.
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
I get this error

"Additional information: Update requires a valid UpdateCommand when
passed DataRow collection with modified rows."

when I try this code.
System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") = "KJHKJHJKHKJ"

If dstPlant.HasChanges() Then

Dim ds2 = dstPlant.GetChanges()

dadPlant.Update(ds2, "plant")

End If

"W.G. Ryan MVP" <Wi*********@nospam.gmail.com> wrote in message
news:Ou****************@TK2MSFTNGP12.phx.gbl...
Jean - before you call update, throw in this line

System.Diagnostics.Debug.Assert(dstPlant.HasChange s(), "There are no
changes present so any updates won't do anything")

If you don't have changes, then nothing is going to happen. Your
getchanges line does nothing here. Typically you'd do something like

DataSet ds2 = dstPlant.GetChanges();
dadPlant.Update(ds2, "plant")

THis will create a dataset of only the changed rows which you would pass
to the adapter (in bandwidth restricted scenarios - this can be a great
boost to performance instead of passing a whole dataset which has many
rows that haven't changed)
"Jean Christophe Avard" <NO***@M.BITCH> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.

I have this code, could anyone tell me if I'm in the good way, cause I
build that code from a book example, but nothing works.

I HAVE THIS CODE TO SAVE THE CHANGE OF THE DATASET

dstPlant.Tables("plant").Rows(intEditRow)("latin_n ame") =
"KLHJJKJKJKHHHHHH"
dstPlant.GetChanges()

dadPlant.Update(dstPlant, "plant")

AND THIS IS THE CODE I USE TO DECLARE THE DATA SET AND DATA ADAPTER

dadPlant = New SqlDataAdapter(STR_SQL_PLANT_SELECT_ALL, cnnSignspro)

' instantiate the sql command

cmmUpdate = New SqlCommand("UPDATE tblItems SET latin_name=@latin_name
WHERE id_item=@id", cnnSignspro)

' instantiater the da update command

dadPlant.UpdateCommand = cmmUpdate

' add update parameter

cmmUpdate.Parameters.Add("@latin_name", SqlDbType.VarChar, 70,
"latin_name")

prmUpdate = dadPlant.UpdateCommand.Parameters.Add("@id_item",
SqlDbType.Int, 4, "id_item")

prmUpdate.Direction = ParameterDirection.Input

prmUpdate.SourceVersion = DataRowVersion.Original

' instantiate the data set

dstPlant = New DataSet("plant")

' fill the data set

dadPlant.Fill(dstPlant, "plant")

ANYONE!?!?!?



Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Hnatt | last post: by
reply views Thread by Vijay Balki | last post: by
5 posts views Thread by PAUL | last post: by
8 posts views Thread by Zorpiedoman | last post: by
6 posts views Thread by Tark Siala | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.