Datagrid updating problems C# form

Discussion in 'Computer Science & Culture' started by carpenoctem112, Feb 23, 2007.

Thread Status:
Not open for further replies.
  1. carpenoctem112 Registered Member

    Messages:
    3
    Firstly, let me say I used to use this forum a while ago and I guess I forgot my login / password, so I had to make a new account.

    now on to the problem.

    I'm using several datagrids to access different tables in a database, I have basically everything working except I can't find out for the life of me what I'm doing wrong in the update method.

    This is exactly what I'm doing to update my datagrid (minus error checking)

    Code:
    DataSet mychangedDs = this.cafeDataSet.GetChanges();
                        if (mychangedDs != null)
                        {
                            //get # of rows changes
                            int modifiedRows = this.pearlTableAdapter.Update(cafeDataSet);
                            MessageBox.Show("Database has been updated successfully: " +
                                modifiedRows + " Modified row(s) ", "Success");
                            this.cafeDataSet.AcceptChanges();
                            //refresh dataset
                            this.cafeDataSet.Clear();
                            pearlTableAdapter.Fill(cafeDataSet.Pearl);
                            pearlData.DataSource = cafeDataSet.Tables["pearl"].DefaultView;
                        }
                        else
                        {
                            MessageBox.Show("Nothing to save", "No changes");
                        }
    Any help would be greatly appreciated.

    P.S. - Wasn't there a "programming" forum before?

    edit: the message box does appear with the correct message, and the datagrid refreshes with the changes, but when I restart the program, all the changes are gone (and not in the database either)
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Blindman Valued Senior Member

    Messages:
    1,425
    I notice that you are mixing you references to the cafeDataSet from “this.cafeDataSet” to “cafeDataSet”
    You may actually have two classes declared. Check your declarations

    For example note the delcrations of the Graphics class
    Code:
    namespace Blindman
    {
        public partial class Form1 : Testing
        {
            public Graphics g;  // decleration of g
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Graphics g;  // second decleration of g
    		// g is valid only in this method
    		// this.g is valid for the class Testing
           }
        }
    }
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. carpenoctem112 Registered Member

    Messages:
    3
    yeah, kind of a practices mistake, I don't actually have two cafedatasets
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. carpenoctem112 Registered Member

    Messages:
    3
    Problem fixed, god I hate visual studios.

    well I can't post the link to the webpage - but needless to say ... my code is RIGHT!! hahaha microsoft makes a copy of the database when you include it in the project which messes stuff up.

    search google for "smart client data working with local databases"
     
Thread Status:
Not open for further replies.

Share This Page