Click here to Skip to main content
16,018,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i have a datagrid which looks like:

subject        students
eg1001         182737H
               29837B
               29837C
               19282W
eg1002         192837C
               32810H

so on and so forth.

how can i do a counter and put into a column between subject and students? like:

subject         numberofstudent   students
eg1001             4              182737H
                                  29837B
                                  29837C
                                  192823W
eg1002              2             192837C
                                  32810H

my codes are as follows:

Dim connect As String
       connect = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\segdata.accdb"
       Dim conn As New OleDbConnection(connect)
       Dim cmd As OleDbCommand = New OleDbCommand
       cmd.Connection = conn
       conn.Open()
       cmd.CommandText = "SELECT DISTINCT ModuleCode, AdminNo FROM(SEGDATA)ORDER BY ModuleCode ASC, AdminNo ASC"
       Dim dt As New DataTable
       dt.Load(cmd.ExecuteReader)
       With dgvmodstud
           .AutoGenerateColumns = True
           .DataSource = dt
       End With
       Dim currentModuleCode As String = String.Empty
       For i = 0 To dgvmodstud.Rows.Count - 1
           If dgvmodstud.Rows(i).Cells(0).Value = currentModuleCode Then
               dgvmodstud.Rows(i).Cells(0).Value = String.Empty
           Else
               currentModuleCode = dgvmodstud.Rows(i).Cells(0).Value
           End If
       Next i
       conn.Close()
       cmd.Dispose()

anyone help me with this?
Posted

1 solution

C#
use  subquery
 
Share this answer
 
Comments
12345_abcde 19-Jul-13 2:22am    
hi thanks for the reply. where do i put it?
how do i do the count until the next modulecode appears?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900