I have crystal report which is working fine when I use DSN
as a datasource.
Problem is I am using dataset now. Dataset contains all the table I need and I am populating it with data from database using Stored procedure.
But, in this way, it is throwing an error : "Missing Parameters
".
I am doing as below :
Step 1 : Creating Dataset1.xsd
and using data connections
inserting all required tables
from database in it.
Step 2 :Giving data source
to report using database expert
as Dataset1.xsd
Step 3 : Populating data using Stored procedure in data set and then creating instance of Dataset1
and merging data from data set to Dataset 1
instance.
My code to fetch data from database and then merge that to Dataset1
instance and giving that as source to crystal report is as below :
Private Sub ReportByDataset(ByVal rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument)
'new code
Dim myConnection As New SqlClient.SqlConnection()
'myConnection.ConnectionString = "server= (local)\NetSDK;database=pubs;Trusted_Connection=yes"
Dim ds As New DataSet1
myConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("HighriseContractingWebConnectionString").ConnectionString
myConnection.Open()
Dim MyCommand As New SqlClient.SqlCommand()
MyCommand.Connection = myConnection
MyCommand.CommandText = "SP_Web_GetReportTables"
MyCommand.CommandType = CommandType.StoredProcedure
Dim MyDA As New SqlClient.SqlDataAdapter()
MyDA.SelectCommand = MyCommand
Dim myDS As New DataSet
MyDA.Fill(myDS)
myConnection.Close()
ds.Tables("RABill_RPT").Merge(myDS.Tables(0), MissingSchemaAction.Ignore)
myDS.Tables(0).Reset()
ds.Tables("RA_bills").Merge(myDS.Tables(1), MissingSchemaAction.Ignore)
ds.Tables("Work_Completion").Merge(myDS.Tables(2), MissingSchemaAction.Ignore)
ds.Tables("contractor").Merge(myDS.Tables(3), MissingSchemaAction.Ignore)
ds.Tables("WO_Header").Merge(myDS.Tables(4), MissingSchemaAction.Ignore)
ds.Tables("Project").Merge(myDS.Tables(5), MissingSchemaAction.Ignore)
ds.Tables("contractor_1").Merge(myDS.Tables(6), MissingSchemaAction.Ignore)
ds.Tables("Users").Merge(myDS.Tables(7), MissingSchemaAction.Ignore)
ds.Tables("Users_Approved").Merge(myDS.Tables(8), MissingSchemaAction.Ignore)
ds.Tables("voucher").Merge(myDS.Tables(9), MissingSchemaAction.Ignore)
ds.Tables("Employee_Approve").Merge(myDS.Tables(10), MissingSchemaAction.Ignore)
ds.Tables("Employee").Merge(myDS.Tables(11), MissingSchemaAction.Ignore)
ds.Tables("Account").Merge(myDS.Tables(12), MissingSchemaAction.Ignore)
ds.Tables("TDS").Merge(myDS.Tables(13), MissingSchemaAction.Ignore)
ds.Tables("WO_Detail").Merge(myDS.Tables(14), MissingSchemaAction.Ignore)
ds.Tables("V_WO_BlockTaskNo").Merge(myDS.Tables(15), MissingSchemaAction.Ignore)
ds.Tables("TASK").Merge(myDS.Tables(16), MissingSchemaAction.Ignore)
ds.Tables("Cont_Voucher").Merge(myDS.Tables(17), MissingSchemaAction.Ignore)
ds.Tables("Cont_Voucher_1").Merge(myDS.Tables(17), MissingSchemaAction.Ignore)
ds.Tables("Cont_Voucher_2").Merge(myDS.Tables(17), MissingSchemaAction.Ignore)
ds.Tables("Company").Merge(myDS.Tables(18), MissingSchemaAction.Ignore)
''new code ends
rptDoc.SetDataSource(ds)
CRReport.HasCrystalLogo = False
CRReport.HasToggleGroupTreeButton = False
CRReport.ReportSource = rptDoc
CRReport.DataBind()
End Sub
But it is not working, what am I missing. Same works fine using DSN
It is not problem of parameters and same is working fine other way.
Note: I know above code is not memory optimised, but my concern for now is to somehow make it work, I can later optimise it
Below image shows Dataset1 as datasource
Two possibilities - where are you getting the parameters missing error thrown? If it is on the stored procedure SP_Web_GetReportTables, you are not adding any parameters for that sproc on MyCommand. If it is on the report itself, check under the Field Explorer on the side of the report itself and see if you have any parameters defined there, that were left over from using the DSN. Since you are now passing in a dataset directly, you don't need to pass any parameters in. Finally, if this is using the Crystal Report Viewer, just setting the ReportSource should display it, I am not sure what the DataBind is doing for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With