我有这个名为" SQLControl"的课程。 我有一个子功能和这样的功能:
Public Function ConnectionTest() As Boolean
Try
SQLConn.Open()
SQLConn.Close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Public Sub LoadTable(LoadTableQuery As String) 'LoadTableQuery itu variable yang ada didalam si Sub LoadTable
Try
SQLConn.Open()
SQLCmd = New SqlCommand(LoadTableQuery, SQLConn) 'Pemakaian LoadTableQuery
'Load SQL record untuk datagrid
SQLDA = New SqlDataAdapter(SQLCmd)
SQLDataset = New DataSet
SQLDA.Fill(SQLDataset)
SQLConn.Close()
Catch ex As Exception
MsgBox(ex.Message)
If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
End If
End Try
End Sub
然后我使用我的子函数到这个:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles pbAdd.Click
Me.Hide()
MenuTambah.cbLokasiPeminjaman.SelectedIndex = 0
MenuTambah.Show()
If SQL.ConnectionTest = True Then
SQL.LoadTable("SELECT * FROM Tabel_Pinjam")
MenuTambah.DGVTambah.DataSource = SQL.SQLDataset.Tables(0)
Else
MsgBox("Koneksi ke database gagal !")
End If
End Sub
然后我想显示名为" DGVTambah"的Datagridview。在" MenuTambah"表格数据集到我的crystalreport,这段代码在我的" MenuTambah"表格:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim myReport As New ReportDocument
myReport.Load(Application.StartupPath & "\Laporan.rpt")
myReport.SetDataSource(DGVTambah.DataSource)
LaporanViewer.CrystalReportViewer1.ReportSource = myReport
End Sub
但它说"报告没有表格",为什么我得到这个错误? 如果没有表格,我的datagridview称为" DGVTambah"不会显示任何表格,我的查询工作正常。 感谢:)