Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: Crystal with .Net Post Reply Post New Topic
Author Message
shraddha_bhatt
Newbie
Newbie


Joined: 17 Nov 2007
Location: India
Online Status: Offline
Posts: 1
Quote shraddha_bhatt Replybullet Topic: Crystal with .Net
    Posted: 17 Nov 2007 at 3:11am
Hello,
               I am working with VB.NET 2.0 and crystal report. I want to display a report to the user which takes one parameter the value for which will be passed through win forms. The data will also be bound to the report during run time. I have written the following code to perform the above task.
 

Imports System.Data.SqlClient

Imports System.Data

Imports CrystalDecisions.Shared

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.ReportSource

Public Class Form1

Dim con As SqlConnection

Dim da As SqlDataAdapter

Dim ds As customers

Dim repdoc As CrystalReport1

Dim paramfield As ParameterField

Dim paramfields As ParameterFields

Dim discval As ParameterDiscreteValue

Dim paramvalues As ParameterValues

Dim frm As New Form2

Dim parameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions

Dim parameterFieldLocation As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition

 

Private Sub btnShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowReport.Click

Try

con = New SqlConnection("server=PSPL664\SA1;database=Northwind;Integrated Security=True;")

da = New SqlDataAdapter("select customerid, companyname, contactname, country from customers", con)

ds = New customers()

da.Fill(ds, "Table2")

repdoc = New CrystalReport1()

paramfield = New ParameterField()

paramfields = New ParameterFields()

discval = New ParameterDiscreteValue()

paramvalues = New ParameterValues()

parameterFieldDefinitions = repdoc.DataDefinition.ParameterFields

parameterFieldLocation = parameterFieldDefinitions.Item(0)

paramvalues = parameterFieldLocation.CurrentValues

discval.Value = cmbCountry.SelectedValue.ToString()

paramvalues.Add(discval)

paramfield.CurrentValues.Add(discval)

paramfields.Add(paramfield)

'ds.WriteXmlSchema("C:\Shraddha\VB2.0\WindowsApplication1\WindowsApplication1\customers.xsd")

repdoc.Load("C:\Shraddha\VB2.0\WindowsApplication1\WindowsApplication1\CrystalReport1.rpt")

repdoc.DataDefinition.ParameterFields(0).ApplyCurrentValues(paramvalues)

repdoc.SetDataSource(ds.Tables(1))

CrystalReportViewer1.ParameterFieldInfo = paramfields

CrystalReportViewer1.ReportSource = repdoc

'CrystalReportViewer1.Refresh()

CrystalReportViewer1.Visible = True

'frm.ShowDialog()

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

con = New SqlConnection("server=PSPL664\SA1;database=Northwind;Integrated Security=True;")

da = New SqlDataAdapter("select distinct country from customers", con)

ds = New customers()

da.Fill(ds, "Table1")

cmbCountry.DataSource = ds.Table1

cmbCountry.DisplayMember = ds.Tables(0).Columns("Country").ToString()

cmbCountry.ValueMember = ds.Tables(0).Columns("Country").ToString()

'frm.CrystalReportViewer1.Visible = True

End Sub

End Class

 

On the click of the button, I am showing the report. When I am trying to display a report, it gives me an "Invalid Pointer" error. I am not able to understand why this error is comming. Data is also passed properly to the report. Still this error comes. Please provide me the solution for the same.

Thanks,
Shraddha
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.