View Full Version : Datagrid updating problems C# form


carpenoctem112
02-22-07, 09:25 PM
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)

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)

Blindman
02-22-07, 11:53 PM
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
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
}
}
}

carpenoctem112
02-23-07, 01:40 AM
yeah, kind of a practices mistake, I don't actually have two cafedatasets

carpenoctem112
02-23-07, 03:47 AM
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"