Vb.net 2010无法加载数据库信息

时间:2014-02-02 19:05:59

标签: vb.net visual-studio-2010 crystal-reports-2010

我非常沮丧,因为我厌倦了在网上寻找这个解决方案.. 每当我尝试从我的数据集加载数据以查看水晶报表

时发生此错误

我在32位PC上使用VS2010 Ultimate。

我的代码如下:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        Cursor = Cursors.WaitCursor

        Dim rpt As New CrystalReport1()
        Dim myConnection As SqlConnection
        Dim MyCommand As New SqlCommand()
        Dim myDA As New SqlDataAdapter()
        Dim myDS As New DataSet1


        myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Projects 2014\sorry\sorry\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
        MyCommand.Connection = myConnection
        MyCommand.CommandText = "select Name from Customer"
        myDA.SelectCommand = MyCommand
        myDA.Fill(myDS, "Customer")
        rpt.SetDataSource(myDS)
        CrystalReportViewer1.ReportSource = rpt
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

End Sub

结束班

2 个答案:

答案 0 :(得分:0)

我修改了上面的代码,以便只是确认,数据也填充在datagridview中..但它不能填充在水晶报表中..同样的错误(无法加载数据库信息)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Projects 2014\sorry\sorry\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

        Dim cmd As New SqlCommand("select name from customer", myConnection)
        Dim ds As New DataSet()
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds)
        DataGridView1.DataSource = ds.Tables(0)
        rpt.SetDataSource(ds.Tables(0))
        CrystalReportViewer1.ReportSource = rpt
    End Sub

答案 1 :(得分:0)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Projects 2014\sorry\sorry\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

    Dim cmd As New SqlCommand("select name from customer", myConnection)
    Dim ds As New DataSet()
    Dim da As New SqlDataAdapter(cmd)
    da.Fill(ds)
    DataGridView1.DataSource = ds.Tables(0)
    rpt.SetDataSource(ds.Tables(0))
    CrystalReportViewer1.ReportSource = rpt

关于windownForm C#