Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hiya guys ... man I love this forum!

 

I'm trying to update data that has been changed by various controls that are on my form.

 

Here is my code. It appears to be right to myself but no matter how I tweak it, it doesn't seem to be working for me :(

 

Try

daClientDetails.Update(dsClientDetails, "Client Details")

MsgBox("Updated!")

Catch dataException As Exception

MsgBox(dataException.Message)

Me.BindingContext(dsClientDetails, "Client Details").CancelCurrentEdit()

End Try

 

Just so it makes sense:

daClientDetails is the DataAdapter

dsClientDetails is the Dataset

"Client Details" is the name of the Table created in MS Access

 

The message box comes up so I know it has used the previous function. When I check if changed data has been saved by "reloading" it again it just brings up the previous set of info. And the error handler doesn't return anything.

 

My load event is written like this:

 

dsClientDetails.Clear()

daClientDetails.Fill(dsClientDetails, "Client Details")

 

 

Any help would be much appreciated. :)

Thanks Guys ... Your help is much appreciated.

 

Bye the way, I love to chat online via messenger and peeps seem to ask me alot my my handle as well. If you wanna then please add energizerbunny101@hotmail.com to your instant messenger.

  • *Experts*
Posted

Check two things first:

Look at dsClientDetails.HasChanges - if it says False then the DataAdapter won't be updating anything.

 

If it's False, check if you have any AcceptChanges calls in your code. AcceptChanges should only be used *after* you update the database.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
Check two things first:

Look at dsClientDetails.HasChanges - if it says False then the DataAdapter won't be updating anything.

 

If it's False, check if you have any AcceptChanges calls in your code. AcceptChanges should only be used *after* you update the database.

 

-ner

 

Hiya, the .HasChanges is currently set to true and there is no AcceptChanges coding at all in my project. Should there be? I set the connections up using the wizard.

Thanks Guys ... Your help is much appreciated.

 

Bye the way, I love to chat online via messenger and peeps seem to ask me alot my my handle as well. If you wanna then please add energizerbunny101@hotmail.com to your instant messenger.

  • *Experts*
Posted

Take a look at what ds.GetXml() returns - see if you can verify that the changes you expect are there. If you're updating SQL Server, try using the profiler to see what SQL string is being executed.

 

Since you get no errors on the Update and you see changes in the DataSet, it seems like things should be working - nothing obvious comes to mind.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
Take a look at what ds.GetXml() returns - see if you can verify that the changes you expect are there. If you're updating SQL Server, try using the profiler to see what SQL string is being executed.

 

Since you get no errors on the Update and you see changes in the DataSet, it seems like things should be working - nothing obvious comes to mind.

 

-ner

 

Thank you for your info ... maybe I'm getting somewhere now.

 

When I use the ds.GetXml() function it shows me updates that I have made. If I change any data in a DataGrid it seems to work but not an ordinary text control.

Thanks Guys ... Your help is much appreciated.

 

Bye the way, I love to chat online via messenger and peeps seem to ask me alot my my handle as well. If you wanna then please add energizerbunny101@hotmail.com to your instant messenger.

  • *Experts*
Posted

You might need to call the DataRow's EndEdit method to "commit" the changes to the DataSet. I believe most grids will do this automagically when you leave focus of the row or grid.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
You might need to call the DataRow's EndEdit method to "commit" the changes to the DataSet. I believe most grids will do this automagically when you leave focus of the row or grid.

 

-ner

 

Er, you couldn't give me some sample code for that could ya?

Thanks Guys ... Your help is much appreciated.

 

Bye the way, I love to chat online via messenger and peeps seem to ask me alot my my handle as well. If you wanna then please add energizerbunny101@hotmail.com to your instant messenger.

  • *Experts*
Posted

If you have a reference to the current row, you simply call dr.EndEdit().

If you're binding to a grid and the textboxes show the details for the currently selected row, then I'd use the grid to get to the right row and call EndEdit. If that won't work, you can use the Form's BindingContext property with the same datasource that you bound to:

 

// Assume your textbox is bound with:
textBox1.DataBindings.Add("Text", ds.Tables["Table1"], "FieldOne");

// Before you try to save, use this:
this.BindingContext[ds.Tables["Table1"]].EndCurrentEdit();

 

You can optionally loop through every row of every table and call EndEdit. Generally, your bound application will know what the current row is.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...