saved to database or not?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: saved to database or not?

  1. #1
    Join Date
    Apr 2005
    Posts
    150

    saved to database or not?

    I use this code to save a new word to my database :

    Code:
    private void btnOpslaan_Click(object sender, EventArgs e)
            {
                System.Data.SqlClient.SqlCommandBuilder cb;
                cb = new System.Data.SqlClient.SqlCommandBuilder(da);
    
                DataRow dRow = ds1.Tables["Woorden"].NewRow();
    
                dRow[1] = txtWoord.Text;
    
                ds1.Tables["Woorden"].Rows.Add(dRow);
    
                iMaxRows++;
                iIndex = iMaxRows - 1;
    
                try
                {
                    da.Update(ds1, "Woorden");
                }
                catch (DBConcurrencyException ex)
                {
                    string customErrorMessage;
                    customErrorMessage = "Concurrency violation\n" + ex.ToString();
                    MessageBox.Show(customErrorMessage);
    
                    // Add business logic code to resolve the concurrency violation...
                    return;
                }
    
                MessageBox.Show("Nieuw woord toegevoegd aan de database.");
    
                btnOpslaan.Enabled = false;
                btnVerwijderen.Enabled = true;
                btnNieuw.Enabled = true;
                btnAnnuleren.Enabled = false;
                txtWoord.Enabled = false;
    
                ReloadDatabase();
            }
    When I close my application and reopen it, my database has the new word in it, but after reopening and closing the application a few times, suddenly the database is to it's old state again?!? What's happening?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,239

    Re: saved to database or not?

    What is 'da' defined as? Are you debugging using thbe Visual Studio IDE? If so, everytime you recompile to start debugging a copy of the db overwrites the old one.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center