Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
10/19/2010 9:37:18 AM EDT
I've got several treenodes in a treeview, some with children some without.  I have 'grammers block today and cannot for the life of me figure out why my "for each node as  treenode in treenodeX.nodes" is only fetching the last child and not each child node.  What gives?
10/19/2010 9:41:54 AM EDT
[#1]
Any chance you have a semicolon at the end of that line?  Post your code.
10/19/2010 10:04:31 AM EDT
[#2]
for each do what?



.NET as in C#, VB ...?
10/19/2010 10:12:42 AM EDT
[#3]
Quoted:
for each do what?

.NET as in C#, VB ...?


In VB ... no semicolons ... trying to solve a performance issue

rsL2A = data.getRS("SELECT * FROM L2Advisors L2A " & _
           "inner join BillingStatus BS on L2A.L2AdvisorID = BS.EntityID " & _
               "and BS.EntityLevel = 'L2Advisor' " & _
           "WHERE BS.BillingPeriod = '" & strBillingPeriod & "' " & _
               "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " " & _
           "order by AdvisorDisplayName")
       Do While Not rsL2A.EOF()
           tnL2A = tvRelationships.Nodes.Add(rsL2A("AdvisorDisplayName").Value, rsL2A("AdvisorDisplayName").Value, getImageIndex(rsL2A("BillingStatusCode").Value), getImageIndex(rsL2A("BillingStatusCode").Value))
           tnL2A.Tag = "L2A-" & rsL2A("L2AdvisorID").Value

           rsAdv = data.getRS("SELECT * " & _
               "FROM Advisors A INNER JOIN BillingStatus BS on A.AdvisorID = BS.EntityID and BS.EntityLevel = 'Advisor' " & _
               "WHERE L2AdvisorID = " & rsL2A("L2AdvisorID").Value & " " & _
                   "and BS.BillingPeriod = '" & BillingPeriod & "' " & _
                   "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " " & _
               "ORDER BY AdvisorDisplayName")
           Do While Not rsAdv.EOF()
               tnAdv = tnL2A.Nodes.Add(rsAdv("AdvisorDisplayName").Value, rsAdv("AdvisorDisplayName").Value, getImageIndex(rsAdv("BillingStatusCode").Value), getImageIndex(rsAdv("BillingStatusCode").Value))
               tnAdv.Tag = "ADV-" & rsAdv("AdvisorID").Value

               rsRel = data.getRS("SELECT pg.PGroupID, pg.DisplayName, pg.advisorID, bs.BillingStatusCode " & _
                   "FROM PortfolioGroups PG Inner join BillingStatus BS on PG.PGroupID = BS.EntityID and BS.EntityLevel = 'PGroup' " & _
                   "where AdvisorID = " & rsAdv("AdvisorID").Value & " " & _
                       "and BS.BillingPeriod = '" & BillingPeriod & "' " & _
                       "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " ")
               Do While Not rsRel.EOF()
                   tnRel = tnAdv.Nodes.Add(rsRel("DisplayName").Value, rsRel("DisplayName").Value, getImageIndex(rsRel("BillingStatusCode").Value), getImageIndex(rsRel("BillingStatusCode").Value))
                   tnRel.Tag = "REL-" & rsRel("PGroupID").Value

                   rsPortfolio = data.getRS("SELECT p.PortfolioID, p.PGroupID, p.DisplayName, bs.BillingStatusCode " & _
                       "FROM Portfolios P INNER JOIN BillingStatus BS on P.PortfolioID = BS.EntityID and BS.EntityLevel = 'Portfolio' " & _
                       "WHERE PGROUPID = " & rsRel("PGroupID").Value & " " & _
                           "and BS.BillingPeriod = '" & BillingPeriod & "' " & _
                           "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " ")
                   Do While Not rsPortfolio.EOF()
                       tnPor = tnRel.Nodes.Add(rsPortfolio("DisplayName").Value, rsPortfolio("DisplayName").Value, getImageIndex(rsPortfolio("BillingStatusCode").Value), getImageIndex(rsPortfolio("BillingStatusCode").Value))
                       tnPor.Tag = "POR-" & rsPortfolio("PortfolioID").Value
                       rsPortfolio.MoveNext()
                   Loop
                   rsPortfolio.Close()

                   rsRel.MoveNext()
               Loop
               rsRel.Close()

               rsAdv.MoveNext()
           Loop
           rsAdv.Close()

           rsL2A.MoveNext()
       Loop

––-

I am simply trying to do

Dim nodeNames as String
For Each node as TreeNode in tnAdv.Nodes
    nodeNames += node.Name
Next

Messagebox.Show(nodeNames)

Instead of getting back a collection of nodes I am only getting the last index of tnAdv
10/19/2010 10:14:15 AM EDT
[#4]
MSDN Help



We use Infragistics controls, so I don't have any sample code using the standard MS Treeview.
10/19/2010 10:23:45 AM EDT
[#5]
Ahh, seeing code like that makes me SO glad I went from MS-languages to UNIX-compatible languages years ago.

I couldn't write Ruby code that ugly if I tried.  

I know Ruby, PHP, Perl, Python, etc. all run on Windows, but that's heresy.
10/19/2010 10:57:32 AM EDT
[#6]
Quoted:
Ahh, seeing code like that makes me SO glad I went from MS-languages to UNIX-compatible languages years ago.

I couldn't write Ruby code that ugly if I tried.  

I know Ruby, PHP, Perl, Python, etc. all run on Windows, but that's heresy.


10/19/2010 2:45:20 PM EDT
[#7]
Sprinkle output statements of the tree's size throughout your code, verify that it's increasing as you expect it to.

Do a test manual output of some of the tree nodes as well, right before your for each loop.

You can do these with the debugger if you know how.

Are you sure that treenodeX is the root node?

Seeing the actual code would be more useful, not just the "what I'm trying to do" paraphrasing and resectioning.  Use code blocks in the arfcom post editor, they're the pound symbol icon next to the image button in the original editor, not sure where exactly they are in the new one.
10/19/2010 2:46:47 PM EDT
[#8]
Write a recursive routine to traverse the tree.
10/19/2010 2:47:48 PM EDT
[#9]
Quoted:
Write a recursive routine to traverse the tree.

This is the other thing I'm unclear on, OP, what's the default traversal for the treeview?  I've never used it.  If you haven't specified one, that may be your problem.
10/19/2010 3:01:09 PM EDT
[#10]
I solved this problem a different way, thanks for the help though.



Traversing the tree by nodes was what I was trying to do but couldn't manage for whateveer reason.  I decided to write one large query and recursively generate the treeview that way, and this was also the fastest way.  Optimizing (somebody elses') code sucks.
10/19/2010 3:01:50 PM EDT
[#11]



Quoted:



Quoted:

Write a recursive routine to traverse the tree.


This is the other thing I'm unclear on, OP, what's the default traversal for the treeview?  I've never used it.  If you haven't specified one, that may be your problem.


I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully.



 
10/19/2010 3:20:07 PM EDT
[#12]
do you do this for a living or is this for class or fun?

had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after.

i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate.

formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are.

i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting.
10/19/2010 3:20:44 PM EDT
[#13]
Does not compute.... but then, I'm a Linux systems administrator...
10/19/2010 3:22:06 PM EDT
[#14]
Quoted:

Quoted:
Quoted:
Write a recursive routine to traverse the tree.

This is the other thing I'm unclear on, OP, what's the default traversal for the treeview?  I've never used it.  If you haven't specified one, that may be your problem.

I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully.
 


if performance is your issue is suggest you write it in win32, with an COM+ OLEDB access method to your db. Put as much of the stuff as you can in the db layer.
10/19/2010 3:25:09 PM EDT
[#15]



Quoted:


do you do this for a living or is this for class or fun?



had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after.



i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate.



formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are.



i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting.


This is a nagging side project for work, this is some old coding that somebody else did not know very much VB (and surprise they have another guy who isn't totally kosher with VB working on it).  Problem 1 for me was that it is using legacy ADODB COM objects instead of new-fangled .NET.  Problem 2 is the awkward continuation ... I'm personally using a string builder, like you said it is faster to develop and troubleshoot.



 
10/19/2010 3:25:59 PM EDT
[#16]





Quoted:





Quoted:
Quoted:




Quoted:


Write a recursive routine to traverse the tree.



This is the other thing I'm unclear on, OP, what's the default traversal for the treeview?  I've never used it.  If you haven't specified one, that may be your problem.



I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully.


 






if performance is your issue is suggest you write it in win32, with an COM+ OLEDB access method to your db. Put as much of the stuff as you can in the db layer.



You posted while I was posting, I'm definitely not using legacy ADO access anymore.  



ETA:  But that is not the main issue, the main issue is/was nesting 4 loops and the 3rd and 4th order loops generating an exponential amount of results (to the tune of hundreds of millions).





 
10/19/2010 3:26:18 PM EDT
[#17]



Quoted:


Does not compute.... but then, I'm a Linux systems administrator...


Bro ... umad?



 
10/19/2010 5:12:57 PM EDT
[#18]
ETA: I just explained a solution unrelated to your problem.
10/19/2010 5:17:28 PM EDT
[#19]
I stopped thinking the moment I learned you were doing this in VB.




10/19/2010 5:25:17 PM EDT
[#20]
Quoted:
do you do this for a living or is this for class or fun?

had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after.

i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate.

formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are.

i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting.


big plus one on code formatting... I cant read what is going on here
10/19/2010 5:26:44 PM EDT
[#21]



Quoted:

big plus one on code formatting... I cant read what is going on here


It probably is, but the forum strips the tabs out. The {code}{/code} tags are there, for just such a thing.



 
10/19/2010 5:37:11 PM EDT
[#22]



Quoted:



Quoted:

do you do this for a living or is this for class or fun?



had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after.



i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate.



formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are.



i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting.




big plus one on code formatting... I cant read what is going on here


Code formatting wasn't what he was talking about ... it's the gay string concatenation in VB.



 
10/19/2010 5:37:15 PM EDT
[#23]

Imports System
Module Module1
   Sub Main()
       Console.WriteLine("Hello World!")
   End Sub
End Module


ETA: what I get for not reading responses.    

but yeah {code}{/code} is useful for things like this although not relevant to the thread apparently.
10/19/2010 5:44:40 PM EDT
[#24]



Quoted:


I stopped thinking the moment I learned you were doing this in VB.





Yup, give me curly braces or give me death!





 
10/19/2010 5:45:20 PM EDT
[#25]



Quoted:





Quoted:

I stopped thinking the moment I learned you were doing this in VB.





Yup, give me curly braces or give me death!



 


Screw the braces,  I want my semi-colons back



 
10/20/2010 9:55:13 AM EDT
[#26]
If anyone cares ... I finally solved it!  App runtime down from 30+ seconds to 1 and change.

        Dim dt As New DataTable

       Dim qry As New System.Text.StringBuilder
       Dim tnL2A As TreeNode
       Dim tnAdv As TreeNode
       Dim tnRel As TreeNode
       Dim tnPor As TreeNode
       Dim startTime As DateTime = DateTime.Now

       qry.Remove(0, qry.Length)
       qry.AppendLine("select a.PortfolioID, a.DisplayName, a.BillingStatusCode, a.PGroupID, a.PGroupName, a.advisorID, a.AdvisorDisplayName, l2a.L2AdvisorID, l2a.EnterpriseName from (")
       qry.AppendLine("select pg.PortfolioID, pg.DisplayName, pg.BillingStatusCode, pg.PGroupID, pg.PGroupName, a.advisorID, a.AdvisorDisplayName, a.L2AdvisorID from (")
       qry.AppendLine("select p.PortfolioID, p.DisplayName, p.BillingStatusCode, pg.PGroupID, pg.PGroupName, pg.advisorID from (")
       qry.AppendLine("select p.PortfolioID, p.PGroupID, p.DisplayName, bs.BillingStatusCode from Portfolios p")
       qry.AppendLine("inner join BillingStatus bs on p.PortfolioID = bs.EntityID and BS.EntityLevel = 'Portfolio'")
       qry.AppendLine("and bs.BillingPeriod = 'Q22010'")
       qry.AppendLine("and bs.advanceFlag = 1 ) as p")
       qry.AppendLine("left outer join (")
       qry.AppendLine("select  pg.PGroupID, pg.DisplayName as PGroupName, pg.advisorID, bs.BillingStatusCode from PortfolioGroups pg")
       qry.AppendLine("inner join BillingStatus bs on pg.PGroupID = bs.EntityID and BS.EntityLevel = 'PGroup'")
       qry.AppendLine("and bs.BillingPeriod = 'Q22010'")
       qry.AppendLine("and bs.advanceFlag = 1 ) as pg")
       qry.AppendLine("on p.PGroupID = pg.PGroupID ) as pg")
       qry.AppendLine("left outer join (")
       qry.AppendLine("select  a.advisorID, a.AdvisorDisplayName, a.L2AdvisorID, bs.BillingStatusCode from advisors a")
       qry.AppendLine("inner join BillingStatus bs on a.advisorID = bs.EntityID and BS.EntityLevel = 'Advisor'")
       qry.AppendLine("and bs.BillingPeriod = 'Q22010'")
       qry.AppendLine("and bs.advanceFlag = 1 ) as a")
       qry.AppendLine("on pg.advisorID = a.advisorID ) as a")
       qry.AppendLine("left outer join (")
       qry.AppendLine("select  l2a.L2AdvisorID, l2a.AdvisorDisplayName as EnterpriseName, bs.BillingStatusCode from L2Advisors l2a")
       qry.AppendLine("inner join BillingStatus bs on l2a.L2AdvisorID = bs.EntityID and BS.EntityLevel = 'L2Advisor'")
       qry.AppendLine("and bs.BillingPeriod = 'Q22010'")
       qry.AppendLine("and bs.advanceFlag = 1 ) as l2a")
       qry.AppendLine("on a.L2AdvisorID = l2a.L2AdvisorID")
       qry.AppendLine("where l2a.L2AdvisorID is not null and a.advisorID is not null and a.PGroupID is not null")
       qry.AppendLine("order by l2a.L2AdvisorID, a.advisorID, a.PGroupID, a.PortfolioID")
       dt = Data.getDT(qry.ToString())

       For Each dr As DataRow In dt.Rows

           If Not TreeView1.Nodes.ContainsKey(dr("EnterpriseName")) Then

               tnL2A = TreeView1.Nodes.Add(dr("EnterpriseName"), dr("EnterpriseName"))
               tnL2A.Tag = "L2A-" & dr("L2AdvisorID")

               If Not tnL2A.Nodes.ContainsKey(dr("AdvisorDisplayName")) Then

                   tnAdv = tnL2A.Nodes.Add(dr("AdvisorDisplayName"), dr("AdvisorDisplayName"))
                   tnAdv.Tag = "ADV-" & dr("AdvisorID")

                   If Not tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       tnRel = tnAdv.Nodes.Add(dr("PGroupName"), dr("PGroupName"))
                       tnRel.Tag = "REL-" & dr("PGroupID")

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   ElseIf tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   End If

               ElseIf tnL2A.Nodes.ContainsKey(dr("AdvisorDisplayName")) Then

                   If Not tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       tnRel = tnAdv.Nodes.Add(dr("PGroupName"), dr("PGroupName"))
                       tnRel.Tag = "REL-" & dr("PGroupID")

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   ElseIf tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   End If

               End If

           ElseIf TreeView1.Nodes.ContainsKey(dr("EnterpriseName")) Then

               If Not tnL2A.Nodes.ContainsKey(dr("AdvisorDisplayName")) Then

                   tnAdv = tnL2A.Nodes.Add(dr("AdvisorDisplayName"), dr("AdvisorDisplayName"))
                   tnAdv.Tag = "ADV-" & dr("AdvisorID")

                   If Not tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       tnRel = tnAdv.Nodes.Add(dr("PGroupName"), dr("PGroupName"))
                       tnRel.Tag = "REL-" & dr("PGroupID")

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   ElseIf tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   End If

               ElseIf tnL2A.Nodes.ContainsKey(dr("AdvisorDisplayName")) Then

                   If Not tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       tnRel = tnAdv.Nodes.Add(dr("PGroupName"), dr("PGroupName"))
                       tnRel.Tag = "REL-" & dr("PGroupID")

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   ElseIf tnAdv.Nodes.ContainsKey(dr("PGroupName")) Then

                       If Not tnRel.Nodes.ContainsKey(dr("DisplayName")) Then

                           tnPor = tnRel.Nodes.Add(dr("DisplayName"), dr("DisplayName"))
                           tnPor.Tag = "POR-" & dr("PortfolioID")

                       End If

                   End If

               End If

           End If

       Next
10/20/2010 10:27:56 AM EDT
[#27]
Needs more: LINQ (or at least stored procedure), DAL, SOA, C#

Good use of StringBuilder vs regular string concatenation but you should be able to instantiate the query string without doing any appending / concatenating anyway.

In C# you can prepend the opening quotes of a string with @, for example:

var someString = @"this
is
completely
valid";


In VB you have to use & _ at the end of each line for the same result:

someString = "this" & _
           "is" & _
           "valid "


Edit: Edited to add that I see that & _ was used in the original code.  StringBuilder is extremely fast but & _ should be faster (the compiler is smart enough to group it all together as a single value rather than concating it  –– this is handled at build time rather than run-time which is where StringBuilder would come into play).
10/20/2010 10:30:58 AM EDT
[#28]
Quoted:
Needs more: LINQ (or at least stored procedure), DAL, SOA, C#

Good use of StringBuilder vs regular string concatenation but you should be able to instantiate the query string without doing any appending / concatenating anyway.

In C# you can prepend the opening quotes of a string with @, for example:
var someString = @"thisiscompletelyvalid";


In VB you have to use & _ at the end of each line for the same result:
someString = "this" & _            "is" & _            "valid "


I hear you but I don't got a choice

The older slower code was written with "& _" and I was not in love with it.
10/20/2010 10:36:30 AM EDT
[#29]
I'm not a fan of VB.NET, but you can use XML literals for multiline strings:

        Dim s As String = <a>SELECT *

FROM TableName
WHERE xyz</a>


or

Dim s As String = <a><![CDATA[SELECT *

FROM TableName
WHERE xyz]]></a>


And the following code seems to work. I'd check to see if your tree isn't populating as expected:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       For i As Integer = 0 To 10
           Dim tn As TreeNode = TreeView1.Nodes.Add(i)
           For j As Integer = 0 To 10
               tn.Nodes.Add(j)
           Next
           For Each nn As TreeNode In tn.Nodes
               nn.Text = "Modified:" + nn.Text
           Next
       Next
   End Sub
10/20/2010 10:41:03 AM EDT
[#30]
In the name of all that is holy, get a DBA to put that in a stored procedure.
10/20/2010 11:05:14 AM EDT
[#31]
Quoted:
In the name of all that is holy, get a DBA to put that in a stored procedure.


If only
10/20/2010 11:34:47 AM EDT
[#32]
10/20/2010 11:42:07 AM EDT
[#33]
Quoted:
In the name of all that is holy, get a DBA to put that in a stored procedure.


No way...multiline parameterized SQL strings are the way to go unless the database functionality is to be consumed by multiple applications. ADO.NET uses sp_executesql behind the scenes which takes advantage of cached execution plans –– essentially, a parameterized SQL statement performs the same as a stored procedure without the side-effect of proliferation of application-specific database objects.
10/20/2010 10:14:33 PM EDT
[#34]



Quoted:



Quoted:

In the name of all that is holy, get a DBA to put that in a stored procedure.




No way...multiline parameterized SQL strings are the way to go unless the database functionality is to be consumed by multiple applications. ADO.NET uses sp_executesql behind the scenes which takes advantage of cached execution plans –– essentially, a parameterized SQL statement performs the same as a stored procedure without the side-effect of proliferation of application-specific database objects.


That's wonderful if your data access requirements NEVER change.  However, none of my projects are like that.  As a result, at least for me, it's MUCH easier to run an ALTER PROCEDURE in the DB rather than build a new exe/dll and deploy it to all the clients.



 
10/20/2010 10:34:50 PM EDT
[#35]
smells like nerd in here

10/20/2010 10:58:14 PM EDT
[#36]
Quoted:
Quoted:
Quoted:
In the name of all that is holy, get a DBA to put that in a stored procedure.

No way...multiline parameterized SQL strings are the way to go unless the database functionality is to be consumed by multiple applications. ADO.NET uses sp_executesql behind the scenes which takes advantage of cached execution plans –– essentially, a parameterized SQL statement performs the same as a stored procedure without the side-effect of proliferation of application-specific database objects.

That's wonderful if your data access requirements NEVER change.  However, none of my projects are like that.  As a result, at least for me, it's MUCH easier to run an ALTER PROCEDURE in the DB rather than build a new exe/dll and deploy it to all the clients.

I'm not sure I can think of any stored procedure change I've ever made that didn't affect the client one way or another.  What kind of thing did you have in mind?  OP's refactoring, I know, but I don't do that very often on the database side.

Anyway, my applications all have just one client; they're custom web apps.
10/20/2010 11:01:23 PM EDT
[#37]
Quoted:
Write a recursive routine to traverse the tree.


Probably not the right solution. I didn't hear any mention of a binary tree.

It sounds like a flat tree in a TreeView, which is represented by an array with child nodes. It's not a classic tree like in computer science.
10/21/2010 6:30:46 AM EDT
[#38]



Quoted:



Quoted:

In the name of all that is holy, get a DBA to put that in a stored procedure.




No way...multiline parameterized SQL strings are the way to go unless the database functionality is to be consumed by multiple applications. ADO.NET uses sp_executesql behind the scenes which takes advantage of cached execution plans –– essentially, a parameterized SQL statement performs the same as a stored procedure without the side-effect of proliferation of application-specific database objects.


That's great until your query needs to change.





 
10/21/2010 1:24:44 PM EDT
[#39]
PSA ... and update 2 (kinda).

Trying to iterate through nodes is fucking retarded, don't do it.  My reward for figuring out the posted code was a slap on the back and not being made fun of for the afternoon.
10/21/2010 1:29:14 PM EDT
[#40]
LINQ that summoabitch.