Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie - group looping process
Message
From
11/09/2006 09:45:17
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
10/09/2006 12:21:42
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Jet/Access Engine
Miscellaneous
Thread ID:
01152652
Message ID:
01152742
Views:
20
>Dear All,
>I am very new to VB.NET, I am using VB.NET 2005 and currently I am trying to do stock group looping process ..(see below)
>
>I need advise from the expert .. do I already have correct codes for such stock group looping process below?
>
>
>Try
>    cn.Open()
>    Dim cmd As New OleDbCommand("SELECT * FROM STOCKS ORDER BY STOCKGROUP,STOCKCODE", cn)
>    Dim dr As OleDbDataReader = cmd.ExecuteReader()
>    Dim mStockGroup as  string, mStockCode as string, mStockName as string
>    If dr.HasRows Then
>        Do While dr.Read
>            mStockGroup = dr("StockGroup")
>            Do While dr.Read and dr("StockGroup") = mStockGroup          ' I am not sure for this part !
>                    mStockCode = dr("StockCode")
>                    mStockName = dr("StockName")
>                    messagebox.show(mStockCode & "   " & mStockName)
>            Loop
>       Loop
>End if
>dr.Close()
>Catch ex As OleDb.OleDbException
>MessageBox.show(ex.Message)
>Catch ex As Exception
>MessageBox.show(ex.Message)
>Finally
>cn.Close()
>End Try
>
Winan,

The code is not correct. It will always skip the first row of the result set. If I may make a suggestion, the code will be much cleaner if you use a DataTable and a DataView to perform grouping on the data. Even better yet - if you already know exactly what sort of aggregations or concatenations you will perform based on the grouping, change the SELECT statement to perform the aggregation on SQL Server.
Previous
Reply
Map
View

Click here to load this message in the networking platform