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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report SQL Connection 1

Status
Not open for further replies.

wvjim

Programmer
Jan 11, 2001
25
0
0
US
I'm new to Crystal Reports and I'm having a bit of trouble getting connected to my database to produce the report. I did a bit of searching and came up with the following code:

CrystalReportViewer1.LogOnInfo(0).ConnectionInfo.ServerName = "SBS2003"
CrystalReportViewer1.LogOnInfo(1).ConnectionInfo.DatabaseName = "CCMS"
CrystalReportViewer1.LogOnInfo(2).ConnectionInfo.UserID = "SA"
CrystalReportViewer1.LogOnInfo(3).ConnectionInfo.Password = "PassMe"
CrystalReportViewer1.DataBind()

This gives me an index error. I sure would appreciate any helpful suggestions.

Thanks in Advance, Jim
 
This is my procedure of calling a report:
first code on some event like button click
rptIzvestaj.Load(Values.PatekaIzvestai() & "Sifrarnici\SifFirmi.rpt", OpenReportMethod.OpenReportByTempCopy)
AddReportConnectionInfo(rptIzvestaj)
AddReportParametar(rptIzvestaj, "@BankaHeader", Values.gsBanka)
crvIzvestai.ReportSource = rptIzvestaj
crvIzvestai.Zoom(1)

There is a two procedures, one for connection info and one for adding a parametar(s). I use SQL server 2000 and for every report I use a stored procedure(s).
Public Sub AddReportConnectionInfo(ByVal rptDoc As ReportDocument)
Dim myTableLogonInfos As New CrystalDecisions.Shared.TableLogOnInfos
Dim myTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim myConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
With myConnectionInfo
.ServerName = Values.Server()
.DatabaseName = Values.databaseST_MK()
.UserID = Values.UID()
.Password = Values.pwd()
End With
myTableLogonInfo.ConnectionInfo = myConnectionInfo
Dim myDatabase As CrystalDecisions.CrystalReports.Engine.Database = rptDoc.Database
Dim myTables As CrystalDecisions.CrystalReports.Engine.Tables = myDatabase.Tables
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

For Each myTable In myTables
myTableLogonInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
End Sub
You must loop all the tables(in my case stored procedures) and apply connection info.
The second function is for parameters.
Public Sub AddReportParametar(ByVal rptDoc As ReportDocument, ByVal ImeNaParametar As String, ByVal Vrednost As String)
Dim crParametarValues As New CrystalDecisions.Shared.ParameterValues
Dim paramValue As New CrystalDecisions.Shared.ParameterDiscreteValue
paramValue.Value = Vrednost
crParametarValues.Add(paramValue)
rptDoc.DataDefinition.ParameterFields(ImeNaParametar).ApplyCurrentValues(crParametarValues)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top