Updating database with dataset

E

EMW

VB.NET question.

I have a number of textboxes bound to a dataset.
When I change some text in one of the textboxes it is nicely updated in the
dataset.
But when I then want to update the database with the changes in this
dataset, DataSet.HasChanges is set to false.

How can this happen?
As far as I know, AcceptChanges is not called.

Can I force the update command to update the database, wheather there are
changes or not?

rg,
Eric
 
M

Miha Markic [MVP C#]

Hi,

You have to invoke BindingManagerBase.EndCurrentEdit() method to commit
changes to DataRow.
 
E

EMW

I don't think that you understand what I mean.

I've got about 100 textboxes bound to the same dataset where a few textboxes
as bound to one table and a few others to another table etc..
When I make a change in one textbox, I see the change in the dataset
(checked by writing it to an XML file).
But the HasChanges value is set to false, although it is clear that the
dataset has at least one change.

So I don't know which cells are changed and obviously the rowstate is not
changed into 'updated'

what now?
If I do need the BindingManagerBase class, how do I use it in this context?

I hope you can/will help me some more?

rg.
Eric




Miha Markic said:
Hi,

You have to invoke BindingManagerBase.EndCurrentEdit() method to commit
changes to DataRow.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

EMW said:
VB.NET question.

I have a number of textboxes bound to a dataset.
When I change some text in one of the textboxes it is nicely updated in the
dataset.
But when I then want to update the database with the changes in this
dataset, DataSet.HasChanges is set to false.

How can this happen?
As far as I know, AcceptChanges is not called.

Can I force the update command to update the database, wheather there are
changes or not?

rg,
Eric
 
C

Cor

Hi Eric,

This sound weird, you know that when you write it to the xml dataset with
ds.WriteXml("c:\emw.xml", XmlWriteMode.DiffGram)
you should see all the updatable changes in that XML file.

Cor
 
E

EMW

Hi Cor,

If I do this with DiffGram, then I get the whole dataset contents and not
just the table with the changed row.
btw, the dataset only holds one record, so each table is just one row.

to be more specific:

The database is a collection of tables about some location information. Each
location has its unique number and every row in each table has at least one
field, that number.
Each table is sort of a chapter about a specific item on that location.
These reports are generated in xml by a PDA program.

The program I'm working on now, is for the people at the office to evaluate
the reports and if needed make changes.

And like I said, these changes are visible in the dataset, but the rows are
not set on UPDATED.

so I can not update the database.

rg,
Eric
 
A

annihil8

Hi

How did you manage to update your database?
I tried this code

connectionAanmelden.Open()
Dim login As String = txtInlogNaam.ToString
datasetAanmelden.Tables(0).Rows(0).Item("name") =
login
adapAanmelden.Update(datasetAanmelden)
connectionAanmelden.Close()

it doesn't give an error, but it doesn't work eather :D

grtz
 
C

Cor

Hi Eric,

It sounds strange and you did that
DirectCast(BindingContext(ds.Tables(0)), CurrencyManager).EndCurrentEdit()

as Miha suggested before the test for haschanges?

Cor
 
M

Miha Markic [MVP C#]

And how is your dataadapter configured?
What's the name of table, etc.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

annihil8 said:
Hi

How did you manage to update your database?
I tried this code

connectionAanmelden.Open()
Dim login As String = txtInlogNaam.ToString
datasetAanmelden.Tables(0).Rows(0).Item("name") =
login
adapAanmelden.Update(datasetAanmelden)
connectionAanmelden.Close()

it doesn't give an error, but it doesn't work eather :D

grtz
 
C

Cor

Hi Annhil,

Is it not easier when we start talking Dutch in this thread.
(I do not mean this serious)

Annhil, when you have a problem it is better to make a new messages, now
Eric thinks it is a correction on his problem.

When Eric has an answer for you he will answer you also on that new message,
you can be sure of that.

I find it strange that you get no error, can you show some of the surrounded
code, (little bit the same as Miha suggested).

Cor
 
E

EMW

thanks Cor,
Miha didn't give me the whole line, so I didn't know what to do with it.
I'm not that experienced in vb.net.

rg,
eric
 
E

EMW

As Miha stated, you will have to let the database know which table to
update.


adapAanmelden.update(datasetAanmelden,"tablename")

it is also better to use

if datasetAanmelden.HasChanges then
adapAanmelden.update(datasetAanmelden.GetChanges,"tablename")
end if

rg,
Eric


annihil8 said:
Hi

How did you manage to update your database?
I tried this code

connectionAanmelden.Open()
Dim login As String = txtInlogNaam.ToString
datasetAanmelden.Tables(0).Rows(0).Item("name") =
login
adapAanmelden.Update(datasetAanmelden)
connectionAanmelden.Close()

it doesn't give an error, but it doesn't work eather :D

grtz
 

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

Top