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)
Related
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()
I have the following code which lets me append a gridview and detailview as PDF file
But what I hope to achieve is not to download it but to attach it as email to send to the designated user. Is there any way I can modify the code so that I can send it as email and instead of download.
Dim strQuery As String = "SELECT * FROM [PointOrder] WHERE PointOrderId =" & Session("PointOrder")
Dim cmd As New SqlCommand(strQuery)
Dim dt As DataTable = GetData(cmd)
Dim DetailsView1 As New DetailsView()
DetailsView1.AllowPaging = False
DetailsView1.DataSource = dt
DetailsView1.DataBind()
Dim strQuery2 As String = "SELECT PointsOrderDetail.RedeemId, Redeem.RedeemName, Redeem.RedeemPoints, PointsOrderDetail.RedeemOrderQuantity, Redeem.RedeemPoints * PointsOrderDetail.RedeemOrderQuantity AS Total_Points FROM PointsOrderDetail INNER JOIN Redeem ON PointsOrderDetail.RedeemId = Redeem.RedeemId WHERE PointsOrderDetail.PointOrderId = " & Session("PointOrder")
Dim cmd2 As New SqlCommand(strQuery2)
Dim dt2 As DataTable = GetData(cmd2)
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.DataSource = dt2
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" & Session("ID") & "-" & Session("PointOrder") & "-RedeemConfirm.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
DetailsView1.RenderControl(hw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
Private Function GetData(ByVal cmd As SqlCommand) As DataTable
Dim dt As New DataTable()
Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("LegacySGConnectionString").ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
con.Close()
sda.Dispose()
con.Dispose()
End Try
End Function
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;
Last time I used two parameter to query & show report. It worked well. Right now I am trying to use same code with another extra parameter but its not working. I am confused. Let me show you my code.
Code which worked well:
Parameter fields : bdate and edate
Crystal report formula : {Bal_sheet.bsdate} >= {?bdate} and {Bal_sheet.bsdate} <= {?edate}
Code to show report :
Private Sub butsbalsrep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsbalsrep.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(Application.StartupPath & "\CrystalReport3.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterFieldDefinitions1 As ParameterFieldDefinitions
Dim crParameterFieldDefinition1 As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterValues1 As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim crParameterDiscreteValue1 As New ParameterDiscreteValue
crParameterDiscreteValue.Value = cmbbdate.Text
crParameterDiscreteValue1.Value = cmbedate.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("bdate")
crParameterFieldDefinitions1 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition1 = crParameterFieldDefinitions.Item("edate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues1 = crParameterFieldDefinition1.CurrentValues
crParameterValues.Clear()
crParameterValues1.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterValues1.Add(crParameterDiscreteValue1)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1)
crysrepbalsht.ReportSource = cryRpt
crysrepbalsht.Refresh()
End Sub
Code which is not working:
Parameter fields : idnmb and acyer and etyp
Crystal report formula : {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp}
Code to show report :
Private Sub butsrrepsr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsrrepsr.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(Application.StartupPath & "\CrystalReport3.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterFieldDefinitions1 As ParameterFieldDefinitions
Dim crParameterFieldDefinition1 As ParameterFieldDefinition
Dim crParameterFieldDefinitions2 As ParameterFieldDefinitions
Dim crParameterFieldDefinition2 As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterValues1 As New ParameterValues
Dim crParameterValues2 As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim crParameterDiscreteValue1 As New ParameterDiscreteValue
Dim crParameterDiscreteValue2 As New ParameterDiscreteValue
crParameterDiscreteValue.Value = cmbsrrepidn.Text
crParameterDiscreteValue1.Value = cmbsrrepay.Text
crParameterDiscreteValue2.Value = cmbsrrepet.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("idnmb")
crParameterFieldDefinitions1 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition1 = crParameterFieldDefinitions.Item("acyer")
crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition2 = crParameterFieldDefinitions.Item("etyp")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues1 = crParameterFieldDefinition1.CurrentValues
crParameterValues2 = crParameterFieldDefinition2.CurrentValues
crParameterValues.Clear()
crParameterValues1.Clear()
crParameterValues2.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterValues1.Add(crParameterDiscreteValue1)
crParameterValues2.Add(crParameterDiscreteValue2)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1)
crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2)
CrystalReportViewer3.ReportSource = cryRpt
CrystalReportViewer3.Refresh()
End Sub
I am confused why its not working! When I click on show report button it shows nothing(I dont get error message and getting no records back.). I have written {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp} it there in formula workshop-record selection formula editor. Please help me to get rid of this problem!
Yes you are right LittleBobbyTables. When I click on show report button it shows nothing(I dont get error message but getting no records back.) Yes I have written {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp} it there in formula workshop-record selection formula editor
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