我用datagrid读取了sql server的数据,可以进行查询,但是我现在的问题是想把当前查询出来的结果打印成报表,不知道哪位老兄能帮帮我啊!!!急!!!谢谢了!!(本人vb刚入门)

解决方案 »

  1.   

    1.你可以把查的数据导出到WORLD或其他格式的文件,下面就是打印了
    2.做报表,把记录集推到报表里面去。
      

  2.   

    不好说,你可以在MSDN里查DATAREPORT这个报表控件,也可以在网上下些其他好的报表工具
      

  3.   

    Print Datagrid Using Datagrid and Adodc Controls http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=31485&lngWId=1
      

  4.   

    还是导出到Excel是最简单的方法,其他的方法你可以慢慢研究
      

  5.   

    用ADO对象连接SQL Server
    定义cn为ADO.connnection
    定义rs为ADO.recordset
    .
    .
    '查询记录
    .
    .
    set datagrid1.datasoure=rs
    set datareport1.datasource=rs
    datasource.show
      

  6.   

    怎么导出到excel啊,我试了很久都没有调成功,不知道哪的问题??
      

  7.   

    给你一段程序.是针对MSHFLEXGRID的.你参考一下..
    '_______________________________________________
    Sub PrintA(PS As Long, PE As Long) '打印成绩表
      Dim a As Long
      Dim B As Long
      Dim GColWidth As Long
      Dim GRowHighe As Long
      Dim LineX As Long
      Dim LineY As Long
      Dim DltP As Long
      Dim PrintR As Long
      Dim FixLab As String
      Dim TmpWidth As Long
      Dim DltH As Long
      Dim PageStar As Long
      Dim PageEnd As Long
      '------------------------------------------------
      ProwStar = 6: PageWidth = 0
      PrintGrid.Cols = PColMax - 1
      
      PrintGrid.RowHeight(-1) = RowHei
      
      PrintGrid.Font.Name = MainFrm.MainGrid.Font.Name
      PrintGrid.Font.Size = MainFrm.MainGrid.Font.Size
      GridLeft = PrintGrid.Left - 0.5 * 567: GridTop = PrintGrid.Top
      DltP = PRowMax - 1
      
      For PageStar = PS To PE
          PrintR = (PRowMax - 1) * (PageStar - 1)
          For a = 1 To PrintGrid.Rows - 1
              For B = 0 To PColMax - 2
                  If (PrintR + a + 5) < MainFrm.MainGrid.Rows Then
                     PrintGrid.TextMatrix(a, B) = MainFrm.MainGrid.TextMatrix(PrintR + a + 5, B + 1)
                  Else
                     PrintGrid.TextMatrix(a, B) = ""
                  End If
             Next B
          Next a
         '开始打印
         Printer.Font.Name = PrintGrid.Font.Name
         Printer.Font.Size = PrintGrid.Font.Size
         Printer.ScaleTop = 0: Printer.ScaleLeft = 0
         Printer.ScaleWidth = Printer.Width + 567
         Printer.ScaleHeight = Printer.Height
         GridTop = PrintGrid.Top: GridLeft = PrintGrid.Left - 0.5 * 567
         LenLab.FontName = PrintGrid.Font.Name
         LenLab.Font.Size = PrintGrid.Font.Size
         DltH = (RowHei - LenLab.Height) \ 2
         '-----------------------------------------------------------------
         PageWidth = PrintGrid.Width
         LineY = GridTop
         For a = 0 To PrintGrid.Rows - 1
             LineX = GridLeft
             '画横线
             Printer.Line (GridLeft, LineY)-(GridLeft + PageWidth, LineY)
             For B = 0 To PrintGrid.Cols - 1
                 TmpWidth = PrintGrid.ColWidth(B)
                 If a = 0 Then
                  '输出表头,并画竖线
                    FixLab = PrintGrid.TextMatrix(0, B)
                    LenLab = FixLab: DoEvents
                    Printer.Line (LineX, GridTop)-(LineX, GridTop + PageHeight)
                    
                    Printer.CurrentX = LineX + (TmpWidth - LenLab.Width) \ 2
                    Printer.CurrentY = LineY + DltH
                    Printer.Print FixLab
                 Else
                   '输出内容
                    Printer.CurrentX = LineX + 45
                    Printer.CurrentY = LineY + DltH
                    Printer.Print PrintGrid.TextMatrix(a, B)
                 End If
                 
                 LineX = LineX + TmpWidth
                 If a = 0 And B = PrintGrid.Cols - 1 Then
                    Printer.Line (LineX, GridTop)-(LineX, GridTop + PageHeight)
                 End If
             Next B
             LineY = LineY + RowHei
             '画最后一条线
             If a = PrintGrid.Rows - 1 Then
                Printer.Line (GridLeft, LineY)-(GridLeft + PageWidth, LineY)
             End If
         Next a
         Label1 = "第" & PageStar & "页"
         If GridLeft + PrintGrid.Width > PrintPic.Width - 1200 Then
            Label1.Left = PrintPic.Width - 1200
         Else
            Label1.Left = GridLeft + PrintGrid.Width - Label1.Width
         End If
         Printer.CurrentX = Label1.Left
         Printer.CurrentY = LineY + 210
         Printer.Print Label1
         DoEvents
         If PageStar < PE Then
            Printer.NewPage
         Else
            Printer.EndDoc
         End If
      Next PageStar
    End Sub