Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got Data grid view on my main form
with tool strip Button where i have connection with 4 tables
when i click on tollstip menu with Table name it shows that selected table
Now when i change something on particular table and make update then i open again that Table where i made a change there is always a old data.
here is my code

C#
public static void SelectTable(string TabName, string orderBy)
       {

           openConnection();
          string query = SELECT * FROM [ + TabName + ] ORDER BY  + orderBy;

           connection = new SqlCeConnection(@Data Source=|DataDirectory|\Db\Applicant.sdf;);
           connection.Open();
           sCommand = new SqlCeCommand(query, connection);
           sAdapter = new SqlCeDataAdapter(sCommand);
           sBuilder = new SqlCeCommandBuilder(sAdapter);

           sDs = new DataSet();
           sAdapter.Fill(sDs, TabName);
           sDs.AcceptChanges();
           sD_Table = sDs.Tables[TabName];//sD_Table is my datatable
           dataGridView.DataSource = sD_Table;
  //this code displays all selected table in mx grid view
}

//now when i change something on gridview


private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
       {
           
           sAdapter.Update(sD_Table);
           this.dataGridView.Refresh();
           here i can c my table is updated
       }

Now when i go back again and select same Table in above code is always with old data

anybody got an idea?????
Posted
Updated 28-Nov-14 3:51am
v2
Comments
OriginalGriff 28-Nov-14 11:16am    
That isn't your code.
I can tell, because that won't compile:

string query = SELECT * FROM [ + TabName + ] ORDER BY + orderBy;

So either you abstracted it badly, or the version you are running is an old version which probably doesn't do the update code at all.
Member 11000455 1-Dec-14 3:17am    
It is my code. u might b wodering what is this + Tabname //here i am gettine my table name for each table i click selected table name in toolstrip menu Button
and order by is ORDER BY DESC which i have initialized as Public yes i didntdisplay each line of code as i think i dont need to.
OriginalGriff 1-Dec-14 3:38am    
No, it isn't.
Try compiling exactly what you have there: and look at the errors list...

And if you don't show us the actual code, we are working to "something like this" - which is like taking a different car to the garage and expecting them to fix the one you left at home. It's the same manufacturer, the same model - so what does it matter?
Member 11000455 1-Dec-14 6:18am    
// This is my main form with datagridview now when u click on menustrip apllicant it loads table given below
public string TableName;
public string OrderBy = "ID DESC";

private void ApplicantTableToolStripMenuItem_Click(object sender, EventArgs e)
{

TableName = "Applicant";
ApllicantDatenbank.SelectTable(TableName, OrderBy);//now this methode is exactly what i have written above here now say Table name is apllicant
//everything working fine but as i say earlier after CellValuechanged is fired
sAdapter.Update(sD_Table);// here i can see my data table is changed but after this line of code it is not saving changed data to my database thats why again when i click on main form tool strip button applicant it loads table with old data reason is clear as it is not updated but why whats wrong so have i think what is wrote is ok?? event cant say i m working with old version as there are other many projects i made earlier working perfectly fine any idea??
after
System.Diagnostics.Debug.WriteLine("SELECT" + TableName.ToString());
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900