473,804 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update data in VB.NET

JamieHowarth0
533 Recognized Expert Contributor
Hi folks,

I'm making a snazzy VB.NET GUI as part of my contract for an asset management firm and it incorporates a TreeView control which I am using to graphically display details of locations, with child nodes for buildings and grandchild nodes as floors per building.

The TreeView nodes are dynamically generated from a SQL Server table (which I cannot disclose details of for confidentiality reasons), however, my problem is pretty generic.

I'm using the HasRows property to check this table for data (so far I've saved two rows of data to it) but it is always returning false on first run (i.e. it can't find those two rows...)
Here's my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub LoadLocationNodes(ByVal ClientID As Integer)
  2. Dim dr_Nodes As DataTableReader
  3. Dim X As TreeNode
  4. Dim parentNodeFind As TreeNode()
  5. Dim parentNode As TreeNode
  6.  
  7. dr_Nodes = Mth_collectDataSet.tbl_data_locns.CreateDataReader()
  8. If dr_Nodes.HasRows Then
  9. 'Clear existing node list
  10. For Each X In tvw_Locations.Nodes
  11. tvw_Locations.Nodes.Remove(X)
  12. Next
  13.  
  14. 'Load node list into TreeView object
  15. While dr_Nodes.Read
  16. Dim tempNode As TreeNode = New TreeNode
  17. Select Case dr_Nodes.Item("ParentID").ToString
  18. Case "", "0", "00000000-0000-0000-0000-000000000000", DBNull.Value.ToString
  19. tempNode.Name = dr_Nodes.Item("LocationID").ToString
  20. tempNode.Text = dr_Nodes.Item("LocationName")
  21. tempNode.Tag = dr_Nodes.Item("ParentID").ToString
  22. If dr_Nodes.Item("VisioMap") IsNot DBNull.Value Then
  23. tempNode.Checked = True
  24. Else
  25. tempNode.Checked = False
  26. End If
  27. tvw_Locations.Nodes.Add(tempNode)
  28. Case Else
  29. tempNode.Name = dr_Nodes.Item("LocationID").ToString
  30. tempNode.Text = dr_Nodes.Item("LocationName")
  31. tempNode.Tag = dr_Nodes.Item("ParentID").ToString
  32. parentNodeFind = tvw_Locations.Nodes.Find(dr_Nodes.Item("ParentID").ToString, True)
  33. For Each parentNode In parentNodeFind
  34. parentNode.Nodes.Add(tempNode)
  35. Next
  36. End Select
  37. tempNode = Nothing
  38. End While
  39. Else
  40. AddNewLocation("0")
  41. End If
  42. End Sub
  43.  
Now, for the first time that this function is run (on form load) the HasRows property returns False, which calls the AddNewLocation sub to add a new record (and node) to the database (and TreeView).
The AddNewLocation then calls the LoadLocationNod es function which then only returns the one (new) node/record instead of 3 (one new + two already in DB).

I am working in Visual Studio 2005 Pro with SQL Server 05 Express Edition and the two rows that I have added have been added using INSERT queries run in design mode. If anyone has any ideas where I'm going wrong and could steer me in the right direction it would be most appreciated.

And last but not least - anyone know how to send an UPDATE method back to the database (fired when someone edits the node label in the TreeView control)?

Many thanks in advance,

medicineworker
Nov 2 '07 #1
0 989

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

Similar topics

16
17026
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
16
3881
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the table, or perhaps bytes, being updated where the engine just decides, screw it, i'll just make a new one. surfed this group and google, but couldn't find anything. the context: we have some java folk who like to parametize/
4
2152
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
6
1730
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... 'OleDbUpdateCommand1 Me.OleDbUpdateCommand1.CommandText = "UPDATE tblGifts SET gift = ?, name = ?, purchased = ? WHERE (autonum = ?) AND (gi" & _ "ft = ? OR ? IS NULL AND gift IS NULL) AND (name = ? OR ? IS NULL AND name IS NUL" & _
8
2700
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
5
2603
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
2
3117
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
5
2182
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
1
5186
by: Selvakumar | last post by:
hai friends, I am new to .net programming. I did the inserting data into MS-access database but i couldn't able to perform the update command. I used only textbox and command button for inserting and updating the data. I performed Insert command successfully but i donno y the update command is not working.Pls help.. i ve used all possible update commands. i enclosed all my code( comments also)... Protected Sub Button1_Click(ByVal sender...
2
2642
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.