473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Data inconsistency in MS Access and OleDb

153 100+
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
2 1490
akshaycjoshi
153 100+
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
akshaycjoshi
153 100+
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

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

Similar topics

0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
4
by: authorking | last post by:
I use the following code to insert a data record in to a datatable of an access database.But every time I execute the command, there will rise an exception and the insert operation can't be...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
4
by: JPO | last post by:
Hi there, I'm trying to use MSAccess as a "container" to move data around from one MS-SQL server DB to another. This is basically already a design decision that has been made for a lot of...
4
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1,...
3
by: SAL | last post by:
Hi, I have Microsoft Enterprise Library 2005 installed on my local system. I'm developing in C# using Visual Studio 2003 IDE with framework 1.1. I am automating a process that will use a DLL...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
9
by: a | last post by:
Dear friends I want import data from CSV file to mdb file How can I do that in vb.net?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.