尚未为vb.net中的数据源数据集1提供数据源实例

时间:2014-10-30 05:07:12

标签: mysql vb.net report

我在使用MySql时遇到问题并在vb.net中报告。我已经安装了MySql ODBC,我的项目已经连接到数据库。但我收到此错误"数据源实例尚未提供给数据源数据集1"。

我是vb.net报告的新手,我们将不胜感激。谢谢。这是我加载数据的代码。

 If con.State = ConnectionState.Open Then

        Dim ds As New DataSet1
        Dim com As New MySqlCommand("select * from tb_course", con)
        Using da As New MySqlDataAdapter(com)
            da.Fill(ds)
        End Using 

        ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local

        ReportViewer1.LocalReport.ReportPath = System.Environment.CurrentDirectory + "\Report1.rdlc"

        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_DataTable1", ds.Tables(0)))

        ReportViewer1.DocumentMapCollapsed = True

        Me.ReportViewer1.RefreshReport()

    End If

2 个答案:

答案 0 :(得分:1)

您需要提供数据集名称和表名

我将为您提供正确运行我的机器的代码

   
Dim ds As New DataSet
    Dim dt As New DataTable
    Dim RpDs1 As New Microsoft.Reporting.WinForms.ReportDataSource
    Dim SQL As String = "select * from mfcount"
    Dim da As New OleDbDataAdapter(SQL, My.Settings.trialConnectionString)
    da.Fill(ds, "mfcount")
    dt = ds.Tables(0)
    ReportViewer1.Reset()
    ReportViewer1.LocalReport.DataSources.Clear()
    RpDs1.Name = "trialDataSet4_MFCount"
    RpDs1.Value = dt
    ReportViewer1.ProcessingMode = WinForms.ProcessingMode.Local
    ReportViewer1.LocalReport.DataSources.Add(RpDs1)
    Dim path = New DirectoryInfo(Application.StartupPath).Parent.Parent.Parent.FullName
    ReportViewer1.LocalReport.ReportEmbeddedResource = Application.StartupPath & "\Report\" & "ADDRESSReport.rdlc"
    ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\Report\" & "ADDRESSReport.rdlc"
    ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
    ReportViewer1.RefreshReport()

此代码可以帮助您..

答案 1 :(得分:0)

感谢basuraj kumbhar帮助您解决这个问题。以下是vb.net中MyCql连接报告的工作代码

Dim ds As New DataSet
    Dim dt As New DataTable
    Dim RpDs1 As New Microsoft.Reporting.WinForms.ReportDataSource
    Dim SQL As String = "select * from tb_course"
    Dim da As New MySqlDataAdapter(SQL, con)

    da.Fill(ds, "tb_course")
    dt = ds.Tables(0)
    ReportViewer1.Reset()
    ReportViewer1.LocalReport.DataSources.Clear()
    RpDs1.Name = "DataSet1"
    RpDs1.Value = dt
    ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local

    ReportViewer1.LocalReport.ReportPath = System.Environment.CurrentDirectory + "\Report1.rdlc"
    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables(0)))

    ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
    ReportViewer1.RefreshReport()