Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble binding dataset to crystal report using vb 1

Status
Not open for further replies.

jheiser

Programmer
Dec 19, 2003
14
US
I am having trouble binding my dataset to my crystal report

I return my dataset from another funtion "ds" and I want to set the results of that data set to my Crystal Reports Viewer.

Does anyone have any advice?

Dim oD As New DBQueries
Dim ds As New DataSet

ds = oD.GetReportSearchResults(MySqlString)
CyrstalReportViewer.ReportSource = ds
 
you are missing lots here.. I use SQL SP's so you can modify the below code to fit yoru needs.


above your page load where the viewer is located, you will need to declare your Crystal report

e.g.

Dim crReportDoc As New YourCrystalReportName

then

in your page load

Dim YourDatasetName As New DataSet

Dim dgCommand As New SqlCommand

With dgCommand
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "YourSPName"
End With

Dim dgDA As New SqlDataAdapter(dgCommand)

cn.Open()

Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table


dgDA.Fill(YourDatasetName, "YourSPName")

crDatabase = crReportDoc.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTable.SetDataSource(YourDatasetName)
Next

YourCrystalReport.ReportSource = crReportDoc

cn.Close()

also look at this

 
I have got my code set up like you have given, but I am having trouble declaring my report name.


Dim crReportDoc As New YourCrystalReportName

My report name is Report0 and is located in my web directory. So I was using

Dim crReportDoc as New Report0

I am getting an error that says Report0 is not declared

I also tried a CrystalReportSource with the name Report0 that was linked to my Report0.rpt file, and I am still recieving the same error message

Any Suggestions?


 
I think you need the .rpt extention:
Code:
Dim crReportDoc As New Report0[b].rpt[/b]
 
Dim crReportDoc As New Report0.rpt

this did not work either
 
make sure you have this in your general declaration

Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared

also right above were you are trying to declar your report make sure you have

Protected WithEvents YourCrystalReport As CrystalDecisions.Web.CrystalReportViewer

 
I am still having trouble getting that report declared. This is what I have so far. Thanks for being patient with me.

I have a "CrystalReportViewer1" as my viewer object
I have "CrystalReport0" as my report name
I created this as new report using ODBC.
I am calling this sub


Imports System.IO
Imports System.Data
Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared

Partial Class MSDSreports
Inherits System.Web.UI.Page
Protected WithEvents CrystalReport0 As CrystalDecisions.Web.CrystalReportViewer
Dim crReportDoc As New CrystalReport0()
Private Sub Search()

'Dim crReportDoc As New Report0
Dim oD As New DBQueries
Dim ds As New DataSet

ds = oD.GetReportSearchResults(MyPassed Values)

Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

crDatabase = crReportDoc.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTable.SetDataSource(ds)
Next
CrystalReportViewer1.ReportSource = crReportDoc
End Sub

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Search()
End Sub
 
I am getting an error that says my CrystalReport0 is not declared at

Dim crReportDoc As New CrystalReport0()
 
take the () off.

also put your code in the page load. this code needs to be in the page load of the form that has the viewer.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top