473,386 Members | 1,820 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,386 software developers and data experts.

Update data in VB.NET

JamieHowarth0
533 Expert 512MB
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 LoadLocationNodes 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 969

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

Similar topics

16
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...
16
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...
4
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...
6
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... ...
8
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. ...
5
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
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...
5
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...
1
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.