0

我正在使用带有 Access 2007 数据库的 VB.NET 2010。我的代码是

    Dim Rpt As New ReportDocument
    Dim PD As New System.Drawing.Printing.PrintDocument
    Dim paramName As String = "", paramAddress As String = "", paramSMan As String = ""

    Dim crtableLogoninfos As New TableLogOnInfos
    Dim crtableLogoninfo As New TableLogOnInfo
    Dim crConnectionInfo As New ConnectionInfo
    Dim CrTables As Tables
    Dim CrTable As Table


    With crConnectionInfo
        .ServerName = Application.StartupPath & "\" & DB
        .DatabaseName = Application.StartupPath & "\" & DB
        .UserID = "Admin"
        .Password = ""
    End With

    Rpt.Load(Application.StartupPath & "\rptBill.rpt")

    CrTables = Rpt.Database.Tables
    For Each CrTable In CrTables
        crtableLogoninfo = CrTable.LogOnInfo
        crtableLogoninfo.ConnectionInfo = crConnectionInfo
        CrTable.ApplyLogOnInfo(crtableLogoninfo)
    Next

    Rpt.RecordSelectionFormula = "{SalesMaster.ID}=" & txtBillNo.Text
    Rpt.Refresh()
    Rpt.PrintOptions.PrinterName = PD.PrinterSettings.PrinterName
    Rpt.PrintToPrinter(1, False, 0, 0)

但是当我运行数据库登录失败错误被触发

请帮我解决这个问题

4

1 回答 1

0

尝试更新 crConnectionInfo 而不是替换它

For Each CrTable In CrTables
    crtableLogoninfo = CrTable.LogOnInfo
    crConnectionInfo = crtableLogoninfo.ConnectionInfo
    With crConnectionInfo
       .ServerName = Application.StartupPath & "\" & DB
       .DatabaseName = Application.StartupPath & "\" & DB
       .UserID = "Admin"
       .Password = ""
    End With

    crtableLogoninfo.ConnectionInfo = crConnectionInfo
    CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
于 2013-08-14T22:07:19.527 回答