By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Data inconsistency in MS Access and OleDb

100+
P: 153
I am making one app. in which i am updating the treeview by reading oen access database.

There is one option of renaming nodes of particular level.

When certain action happens (like renaming the nodes etc) I refresh the treeview.

When i perform renaming it gets renamed in the Access database but the changes are not reflected in the refreshing function.

For proof i am attaching the picture.

P.S. For updating the database i use the connected version(ExecuteNonQuery) and while refreshing, i use the disconencted version.(DataAdapter.Fill)

When i restart the app (when refreshing is done once in the formload event) I can see the actual nodes (as in the database) !

Where am I going wrong ?

Real time:



After restart of app:

Jan 13 '09 #1
Share this Question
Share on Google+
2 Replies


100+
P: 153
Seems like i will have to do the following to get rid of it in the AfterLabelEdit event.


e.CancelEdit =true
treeexchange.LabelEdit = false;
treeexchange.SelectedNode.EndEdit(false);

Working OK after this , will get back if anything bad happens :)

Thanks !
Jan 13 '09 #2

100+
P: 153
It has sorted out the problem but still I am confused about what is actually happening.
Here is my code

[SIZE=2][/SIZE]
Expand|Select|Wrap|Line Numbers
  1.  
  2. if (e.Label == null || e.Label.Trim()=="")
  3. {
  4. e.CancelEdit = true;
  5. return;
  6. }
  7. foreach (char c in e.Label)
  8. {
  9. if ((char.IsLetter(c) == false & char.IsDigit(c) == false) | (char.IsWhiteSpace(c)==true) )
  10. {
  11. MessageBox.Show("Only letters and digits are allowed ", "Call Analyzer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  12. e.CancelEdit = true;
  13. treeexchange.SelectedNode.BeginEdit();
  14. return;
  15. }
  16. }
  17. e.CancelEdit = true;
  18. treeexchange.LabelEdit = false;
  19. treeexchange.SelectedNode.EndEdit(false);
  20. OleDbConnection renamegroupcon = null;
  21. OleDbCommand renamegroupextcom = null;
  22. OleDbCommand renamegroupgrpcom = null;
  23. try
  24. {
  25. renamegroupcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\exchangesandtrunks.mdb;Persist Security Info=False");
  26. renamegroupcon.Open();
  27. renamegroupgrpcom = new OleDbCommand("update t_extensiongroups set group_name='" + e.Label + "' where group_name='" + treeexchange.SelectedNode.Text + "'", renamegroupcon);
  28. renamegroupgrpcom.ExecuteNonQuery();
  29. renamegroupextcom = new OleDbCommand("update t_extensions set group_name='" + e.Label + "' where group_name='" + treeexchange.SelectedNode.Text + "'", renamegroupcon);
  30. renamegroupextcom.ExecuteNonQuery();
  31. }
  32. catch (Exception ex)
  33. {
  34. MessageBox.Show("An error occured while trying to rename the group.(Group already exists ?)", "Call Analyzer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  35. try
  36. {
  37. string error = Environment.NewLine + "*****error****" + System.Environment.NewLine + DateTime.Now.ToString() + System.Environment.NewLine + ex.Message + System.Environment.NewLine + ex.StackTrace;
  38. File.AppendAllText(Application.StartupPath + @"\application_data\error.txt", error);
  39. }
  40. catch
  41. {
  42. MessageBox.Show("Call analyzer has been tempered with.Please contact author", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  43. }
  44. }
  45. finally
  46. {
  47. if (renamegroupcon.State == ConnectionState.Open)
  48. renamegroupcon.Close();
  49.  
  50. refreshtree();
  51. treeexchange.Nodes[0].Expand();
  52. foreach (TreeNode n in treeexchange.Nodes[0].Nodes)
  53. if (n.Text == e.Label)
  54. n.Expand();
  55. }
  56.  
The refreshtree function is as before.

Expand|Select|Wrap|Line Numbers
  1.  
  2. {
  3.            treeexchange.Nodes.Clear();
  4.             TreeNode extensionsnode = new TreeNode("Extensions");
  5.             treeexchange.Nodes.Add(extensionsnode);
  6.             DataTable dtgroups = new DataTable(); //get groups
  7.             OleDbDataAdapter adp = new OleDbDataAdapter("select group_name,group_date_of_creation ,group_no_of_extensions from t_extensiongroups", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\exchangesandtrunks.mdb;Persist Security Info=False");
  8.             adp.Fill(dtgroups);
  9.             //when the user points to this it shows the details of the extension
  10.             extensionsnode.ToolTipText = "No of groups: " + dtgroups.Rows.Count.ToString();
  11.             int totalextensions = 0;
  12.             for (int i = 0; i < dtgroups.Rows.Count; i++)//for all the groups
  13.             {
  14.                 //create a groupnode with the group name in it
  15.                 TreeNode groupnode = new TreeNode(dtgroups.Rows[i]["group_name"].ToString());
  16.                 groupnode.ToolTipText = "Group name: " + dtgroups.Rows[i]["group_name"].ToString();
  17.  
  18.                 //get no of extensions corresposnding to that group
  19.                 adp = new OleDbDataAdapter("select ext_name,group_name,ext_number,ext_date_of_creation from t_extensions where group_name='" + dtgroups.Rows[i]["group_name"].ToString() + "'", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\exchangesandtrunks.mdb;Persist Security Info=False");
  20.                 DataTable dtextensions = new DataTable("Extensions");
  21.                 adp.Fill(dtextensions);
  22.                 int totalgrpextensions = 0;
  23.                 //add all the extension nodes to the groupnode
  24.                 //
  25.                 for (int j = 0; j < dtextensions.Rows.Count; j++)
  26.                 {
  27.                     TreeNode extensionnode = new TreeNode(dtextensions.Rows[j]["ext_number"].ToString() + " (" + dtextensions.Rows[j]["ext_name"].ToString()+ ")");
  28.                     groupnode.Nodes.Add(extensionnode);
  29.                     extensionnode.ToolTipText = "Extension name: " + dtextensions.Rows[j]["ext_name"].ToString() + "\nExtension no: " + dtextensions.Rows[j]["ext_number"].ToString() + "\nExtension group: " + dtextensions.Rows[j]["group_name"].ToString() + "\nCreated: " + dtextensions.Rows[j]["ext_date_of_creation"].ToString();
  30.                     totalextensions++;
  31.                     totalgrpextensions++;//for setting the tool tip groups wise
  32.                 }
  33.                 //add the groupnode
  34.                 extensionsnode.Nodes.Add(groupnode);
  35.                 //add the tooltip to this groupnode
  36.                 groupnode.ToolTipText += "\nNo of extensions: " + totalgrpextensions.ToString() + "\n" + "Created: " + dtgroups.Rows[i]["group_date_of_creation"].ToString();
  37.             }
  38.  
  39.             //got all the details about the extension now fill it !
  40.             extensionsnode.ToolTipText += "\nNo of extensions: " + totalextensions.ToString();
  41.  
  42.             //create a trunk node
  43.             TreeNode trunksnode = new TreeNode("Trunks");
  44.             //get trunks
  45.             adp = new OleDbDataAdapter("select trunk_connected_trunk,trunk_name,trunk_virtual_number,trunk_date_of_creation from t_trunk_lines", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\exchangesandtrunks.mdb;Persist Security Info=False");
  46.             DataTable dttrunks = new DataTable("Trunks");
  47.             adp.Fill(dttrunks);
  48.             //add all trunks to the "trunks" node
  49.             for (int i = 0; i < dttrunks.Rows.Count; i++)
  50.             {
  51.                 TreeNode trunknode = new TreeNode(dttrunks.Rows[i]["trunk_virtual_number"].ToString() + " (" + dttrunks.Rows[i]["trunk_connected_trunk"].ToString() + ")");
  52.                 trunksnode.Nodes.Add(trunknode);
  53.                 trunknode.ToolTipText = "Trunk name: " + dttrunks.Rows[i]["trunk_name"].ToString() + "\nConnected trunk: " + dttrunks.Rows[i]["trunk_connected_trunk"].ToString() + "\nVirtual trunk no:" + dttrunks.Rows[i]["trunk_virtual_number"].ToString() + "\nCreated:" + dttrunks.Rows[i]["trunk_date_of_creation"].ToString();
  54.             }
  55.             //add the trunk node
  56.             treeexchange.Nodes.Add(trunksnode);
  57.             //add the tag to this "trunks" node
  58.             trunksnode.ToolTipText = "Number of trunks: " + dttrunks.Rows.Count.ToString();
  59.             //add the pbx node
  60.             TreeNode pbxnode = new TreeNode("Settings");
  61.             pbxnode.ToolTipText = "Serial port and other settings";
  62.             treeexchange.Nodes.Add(pbxnode);
  63.             //add the User node
  64.             TreeNode usernode = new TreeNode("User");
  65.             usernode.ToolTipText = "User";
  66.             treeexchange.Nodes.Add(usernode);
  67. }
  68.  
If I remove those three lines it gets messed up even when i am writing
treeexchange.Nodes.Clear(); in the function.

Can anyone point some light on it ?

Also is there are other event where i can call refreshtree() ??
After label edit fires before the changes are committed on the treeview.
I just need to cancel all editing and then call refreshtree() after all database updating has been done.
Jan 14 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.