When the crystal report calls the stored procedure, the table cannot be found due to an error. solution.

Source: Internet
Author: User
Tags odbc connection




Use the crystalreportviewer1 control to display the Report on the Asp.net webpage. If you call the data table method when creating a report, the call is successful. However, if you use the stored procedure to obtain data in a report, the following error occurs:


The table 'rptopencheck; 1' is not found '. File G: \ temp \ fo-opencheck {6d191f06-decf-4a25-88fc-8553e3d435aa}. rpt error: the table cannot be found.
Error: the object reference is not set to the instance of the object.


The table 'rptopencheck; 1 'could not be found. Error in file G: \ temp \ fo-opencheck {6d191f06-decf-4a25-88fc-8553e3d435aa}. rpt: The table cocould not be found.




The connection cannot be opened. The connection cannot be opened. G: \ temp \ fo-opencheck {4e60249e-fc16-4f3d-a610-138fc3297171}. rpt


Vs2005 environment, crsytal reports 11.5


The Code is as follows:


Dim crtablelogoninfos as new tablelogoninfos
Dim crtablelogoninfo as new tablelogoninfo
Dim crconnectioninfo as new connectioninfo
Dim crparameterfields as parameterfields
Dim crparameterfield as parameterfield
Dim crparametervalues as parametervalues
Dim crparameterdefvalues as parametervalues
Dim crparametervalue as parametervalue
Dim crparameterdiscretevalue as parameterdiscretevalue


Dim crtables as tables
Dim crtable as table


Dim reportname as string
Dim printto as string 'P printer V window
Dim reportpath as string
Dim username as string
Dim password as string
Dim servername as string
Dim databasename as string
Dim crreportdocument as new reportdocument




Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load, me. Load


Dim strparam as string = request ("p ")


'Get user request parameters
If right (strparam, 1) = "~ "Then
Strparam = mid (strparam, 1, Len (strparam)-1)
End if


'Parameter conversion to array
S = Split (strparam ,"~ ")


'Use ODBC Connection database
With crconnectioninfo
. Allowcustomconnection = true
. Servername = "odbcname"
'. Databasename = "tempdb"
. Userid = "sa"
. Password = "microwin"
End


''Use SQL Connection database
'With crconnectioninfo
'. Allowcustomconnection = true
'. Servername = "(local )"
'. Databasename = "tempdb"
'. Userid = "sa"
'. Password = "microwin"
'End

'Specify the report path
Reportpath = server. mappath (request. applicationpath)
Reportnamepath = reportpath & "\ Testing. rpt"


'Check report file exists and load report
If system. Io. file. exists (reportnamepath) then
Crreportdocument. Load (reportnamepath)
End if

'Set the report document to the report control.
Me. crystalreportviewer1.reportsource = crreportdocument

'Set database connection information to report documents
Crtables = crreportdocument. database. Tables
For each crtable in crtables


Crtablelogoninfo = crtable. logoninfo
Crtablelogoninfo. connectioninfo = crconnectioninfo
Crtable. applylogoninfo (crtablelogoninfo)


'That is, this sentence is not added, so the above error message will appear. Only when the report calls the stored procedure to retrieve data will an error occur. It took me a few days to finally solve the problem.
Crtable. Location = crtable. Name
Next


'Set the properties displayed by the control.
With crystalreportviewer1


. Autodatabind = true
. Reuseparametervaluesonrefresh = true
. Enabledatabaselogonprompt = false
. Enableparameterprompt = false


Crystalreportviewer1.displaygrouptree = false
Crystalreportviewer1.displaypage = true
Crystalreportviewer1.displaytoolbar = true
Crystalreportviewer1.reportsource = crreportdocument


End


If not ispostback then


'Assign a value to the report using the parameters requested by the user. If the report requires parameters, the report parameter value starts from the third element.


Crparameterfields = nothing
Crparameterfields = crystalreportviewer1.parameterfieldinfo


Dim J as integer = ubound (s, 1)

For I = 0 to crparameterfields. Count-1
Crparameterfield = crparameterfields. Item (I)


Crparametervalues = crparameterfield. currentvalues


Crparameterdefvalues = nothing
Crparameterdefvalues = new parametervalues
Crparameterdefvalues = crparameterfield. defaultvalues


Crparameterdiscretevalue = nothing
Crparameterdiscretevalue = new parameterdiscretevalue


If I> (J-2) then


Select case crparameterfield. parametervaluekind
Case parametervaluekind. booleanparameter
Crparameterdiscretevalue. value = false
Case parametervaluekind. currencyparameter
Crparameterdiscretevalue. value = nothing
Case parametervaluekind. dateparameter
Crparameterdiscretevalue. value = system. datetime. Now
Case parametervaluekind. datetimeparameter
Crparameterdiscretevalue. value = system. datetime. Now
Case parametervaluekind. numberparameter
Crparameterdiscretevalue. value = nothing
Case parametervaluekind. stringparameter
Crparameterdiscretevalue. value = ""
Case parametervaluekind. timeparameter
Crparameterdiscretevalue. value = system. datetime. Now
End select


Crparametervalues. Add (crparameterdiscretevalue)


Else


Select case crparameterfield. parametervaluekind
Case parametervaluekind. booleanparameter
Crparameterdiscretevalue. value = IIF (S (I + 2) = "0", false, true)
Case parametervaluekind. currencyparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", nothing, S (I + 2 ))
Case parametervaluekind. dateparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", nothing, S (I + 2 ))
Case parametervaluekind. datetimeparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", nothing, S (I + 2 ))
Case parametervaluekind. numberparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", nothing, S (I + 2 ))
Case parametervaluekind. stringparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", "", S (I + 2 ))
Case parametervaluekind. timeparameter
Crparameterdiscretevalue. value = IIF (TRIM (S (I + 2) & "") = "", nothing, S (I + 2 ))
End select


Crparametervalues. Add (crparameterdiscretevalue)
End if


Next




End if

End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.