Click here to Skip to main content
15,886,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I really want to have an output of :

Name Age Subjects Grade
Justin|13
------------- Math --- 80
------------- English--- 80



I have a select inner join SQL Query like this:

SELECT Student.* , Subject.* FROM  SubjectINNER JOIN Buyer_Table ON Subject.subjID = Student.studId"


with this code:

Private Sub ButtonExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim rowsTotal, colsTotal As Short
       Dim I, j, iC As Short
       System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
       Dim xlApp As New Excel.Application
       Try
           Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
           Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
           xlApp.Visible = True
           rowsTotal = DataGridView1.RowCount - 1
           colsTotal = DataGridView1.Columns.Count - 1
           With excelWorksheet
               .Cells.Select()
               .Cells.Delete()
               For iC = 0 To colsTotal
                   .Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
               Next
               For I = 0 To rowsTotal - 1
                   For j = 0 To colsTotal
                       .Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value

                       If j = 15 Then
                           .Cells(I + 5, j + 1).value = DataGridView1.Rows(I).Cells(j).Value


                       End If

                   Next j
               Next I
               .Rows("1:1").Font.FontStyle = "Bold"
               .Rows("1:1").Font.Size = 10
               .Cells.Columns.AutoFit()
               .Cells.Select()
               .Cells.EntireColumn.AutoFit()
               .Cells(1, 1).Select()
           End With
       Catch ex As Exception
           MsgBox("Export Excel Error " & ex.Message)
       Finally
           'RELEASE ALLOACTED RESOURCES
           System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
           xlApp = Nothing
       End Try
   End Sub




But all I can create is this:

Name Age Subjects Grade
Justin 13 Math 80
Justin 13 English 80


Any ideas on how to make it?
Posted

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