Saving Database records

G

Guest

Hello I am new to C# compact framework. I have been working on a WinMobile
app that everything seems to work correctly, I get no errors. But..... While
debugging in the PocketPC WM 5.0 when I insert a new record or edit an
existing record (created in database designer)the changes are never actually
saved. Here's an example.
Form1 --Buttons that take me to the data grid form
Form 2 --Data Grid form
Form 3 -- Data Edit View form
If I click the new button on form2 it inserts a new record and takes me to
the Data Edit form. Here I edit any data I choose, then click the OK button,
which returns me to the Data Grid form. After returning to the grid form all
the data is present, I can even tap the grid and re edit the data I just
entered.
But if I open the query analyzer on the emulator and open the table and
click Refresh the table does not show the new records I just inserted or
edited. All editing and inserting is done by the forms that VS2005 created
for me by clicking the arrow on top of the grid in design mode and selecting
generate data forms. If I close form2 but not the entire application my new
data also disapears. Is this just because I am debugging?

Any help would be gratly appreciated.
Jon Stroh
 
J

Jim Hughes

Is it possible that the database is being replaced each time that you go
into debug with the version on the development pc?

If the database is present in the solution, change the compile property from
"Content" to "None"
 
G

Guest

Hello Jim
Thanks for that idea, I tried that and then I got a database does not exist
error. So I copied the .sdf file to the device and ran the application again.
Then the app ran fine. The data however was still not saved. If I close the
grid form and re open it it still does not show the records I added.
Here is my code for saving changes to the db, is it possible that my fill()
is not seeing the saved data for some reason?
this.horseBindingSource.EndEdit();
FB7MobileDBDataSet fb7mobiledataset = new FB7MobileDBDataSet();
FB7MobileDBDataSet.HorseDataTable newhorse =
(FB7MobileDBDataSet.HorseDataTable)
fb7mobiledataset.Horse.GetChanges(DataRowState.Added);

try
{
if (newhorse !=null)
{
horseTableAdapter1.Update(newhorse);
}
fb7mobiledataset.AcceptChanges();
}
catch (System.Exception ex)
{
MessageBox.Show("UpdateFailed" + ex.Message);
}
finally
{
if (newhorse != null)
{
newhorse.Dispose();
}
}
Thanks Jon Stroh
 
J

Jim Hughes

Copying the db outside of the solution is the right way to go.

This line
fb7mobiledataset.Horse.GetChanges(DataRowState.Added);
will only get newly inserted records, not updated records, you need to also
look for DataRowState.Modified

You should not need to use AcceptChanges, that is called automatically by
the Update method.

You may also want to use the HasChanges method to see if changes have been
made.
 
J

Jim Hughes

Copying the db outside of the solution is the right way to go.

This line
fb7mobiledataset.Horse.GetChanges(DataRowState.Added);
will only get newly inserted records, not updated records, you need to also
look for DataRowState.Modified

You should not need to use AcceptChanges, that is called automatically by
the Update method.

You may also want to use the HasChanges method to see if changes have been
made.
 

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