I can't display any result in crystal report - crystal-reports

i'm developing a web app and I can't display any result to my crystal report. i don't know what is wrong in my code. please help.
Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String
connectionString = "data source=SERVERNAME; _
initial catalog=crystaldb;user id=sa;password=PASSWORD;"
cnn = New SqlConnection(connectionString)
cnn.Open()
sql = "SELECT * FROM Grades
Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet1
dscmd.Fill(ds, "Grades")
objRpt.SetDataSource(ds.Tables(1))
CrystalReportViewer1.ReportSource = objRpt
CrystalReportViewer1.RefreshReport()

Related

Crystal reports asking for user and password

i am using crystal reports and vb.net
whenever user or i as developer open crystal report, it ask for user and password. my code that i am using in vb.net is below. how can i disable it
my codes are
enter code here
Dim cryRpt As New ReportDocument
cryRpt.Load("\\192.168.1.150\Bashir Impex
Files\Department Folders\IT\cpv.rpt")
Dim crParameterFieldDefinitions As
ParameterFieldDefinitions
Dim crParameterFieldDefinition As
ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New
ParameterDiscreteValue
crParameterDiscreteValue.Value = TextBox2.Text
crParameterFieldDefinitions = _
cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = _
crParameterFieldDefinitions.Item("cpvid")
crParameterValues =
crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Form5.CrystalReportViewer1.ReportSource = cryRpt
Form5.CrystalReportViewer1.Refresh()
Form5.Show()
problem solved by adding one line to my code
cryRpt.SetDatabaseLogon(user, pwd)

Crystal Reports - how to pass parameter?

I would like to pass a parameter to my report and put the report into my project.
I want to pass a user id as parameter to the report.
The id will be different each time.
Can someone help me on this topic how to pass the parameter.
Here is my code so far:
CrystalReportViewer1.Visible = True
Dim rDoc As New ReportDocument()
' Crystal Report Name
rDoc.Load(Server.MapPath("Sucess.rpt"))
' Your .rpt file path
'set dataset to the report viewer.
CrystalReportViewer1.ReportSource = rDoc
You can try something like this:
string ponumber;
string receiptno;
ponumber = TextBox1.Text;
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);

Crystal Reports in VB.net with datatable

!!
I'm using crystal report in my project of vb.net. I'm using visual studio 2010,sql server2008 and SAP crystal report.there is an error that i can not overcome/solve.here is my code:
Dim database As New Database
Dim dr As DataRow
Dim dt As Data.DataTable
Dim report As New CrystalReportChalan
Dim query1 As String
Try
query1 = "select per_name,f_name,per_address,rem_amount from person_info "
database.creatConn()
dt = database.getDS(query1, "person_info")
'dr = dt.Rows(0)
MessageBox.Show(dt.Rows.Count) // Here the no of rows displayed
report.SetDataSource(dt) //Error 'Report has no table'
CrystalReportViewer1.ReportSource = report
CrystalReportViewer1.Refresh()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
there is a separated class for Database connection
that class has function to get data from database.

How to textbox value as a parameter in crystal report?

How to pass textbox values as parameter in crystal report in asp.net C#?
I want example which shows steps to passparamter
I have tried many examples but no output..
I want as in below link
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-string-parameter.htm
But no data is displaying
Pls help
try this code
ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "#CustomerName";
paramDiscreteValue.Value = TextBox1.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
reportDocument.Load(Server.MapPath("CrystalReport.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
I hope this will help:
ReportDocument cryReportDocument = .......;
cryReportDocument.SetDatabaseLogon("userName", "password");
cryReportDocument.SetParameterValue("parameterName", yourTextBoxName.Text);
CrystalReportViewer1.ReportSource = cryReportDocument;

Crystal report create connection to OLE DB database

I am working with VS 2005 and using visual basic for coding.
How do I set up the connection object for my crystal report using vb code.
I have written some code
Dim strcon As String = ConfigurationManager.AppSettings("PhdConnectionString")
Dim getconn As SqlConnection = New SqlConnection(strcon)
Dim rpt As ReportDocument = New ReportDocument
rpt.Load(Server.MapPath("aspirantCrystalReport.rpt"))
// I want to set the connection properties here. How do I do that ?
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.DataBind()
I have not done this using the Crystal Reports .NET API, but I do have a working piece of code written in VB6 that calls the COM API. The API class and member names can't be that different.
Private Sub SetDataConnections(ByVal oReport As CRAXDRT.Report, ByVal oConnection As ADODB.Connection)
' Do all tables in this report.
Dim oTable As CRAXDRT.DatabaseTable
For Each oTable In oReport.Database.Tables
SetDataConnection oTable, oConnection
Next
' Find all subreports and do them too.
Dim oSection As CRAXDRT.Section
For Each oSection In oReport.Sections
Dim oObject As Object
For Each oObject In oSection.ReportObjects
If TypeOf oObject Is CRAXDRT.SubreportObject Then
Dim oSubreportObject As CRAXDRT.SubreportObject
Set oSubreportObject = oObject
SetDataConnections oSubreportObject.OpenSubreport()
Set oSubreportObject = Nothing
End If
Next
Next
End Sub
Private Sub SetDataConnection(ByVal oTable As CRAXDRT.DatabaseTable, ByVal oConnection As ADODB.Connection)
' Extract the relevant data from the ADO connection.
Dim sServer As String
Dim sDatabase As String
Dim bTrusted As String
Dim sUserName As String
Dim sPassword As String
Dim nTimeout As Long
With oConnection.Properties
sServer = .Item("Data Source").Value
sDatabase = .Item("Initial Catalog").Value
Select Case UCase(.Item("Integrated Security").Value)
Case "SSPI", "YES"
bTrusted = True
Case Else ' "NO", ""
bTrusted = False
End Select
sUserName = .Item("User ID").Value
sPassword = .Item("Password").Value
End With
nTimeout = oConnection.CommandTimeout
' Delete and re-create all connection information. This is the only way of getting it
' to work if the report contains subreports. Changing database drivers on the fly is
' not allowed, so we must re-create the connection using settings appropriate for the
' particular driver involved.
Select Case oTable.DllName
Case "crdb_ado.dll"
With oTable.ConnectionProperties
.DeleteAll
.Add "Database Type", "OLE DB (ADO)"
.Add "Provider", "SQLOLEDB"
.Add "Data Source", sServer
.Add "Initial Catalog", sDatabase
.Add "Integrated Security", bTrusted
.Add "User ID", sUserName
.Add "Password", sPassword
.Add "OLE DB Services", -1
.Add "General Timeout", nTimeout
End With
Case Else
' TODO: Handle other drivers appropriately.
End Select
End Sub