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

runtime report

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
By using ado,how to assign resultsets into crystalreports at runtime.
 
Here is the code in VB that will bind the recordset field during run time. Create CRC designer called crUnboundReport with two unbound fields UnboundField1(number type) and UnboundString1 string type. Create two text boxes Text1 and Text2 that will hold the fieldnames in the unbound report.

Dim rs As New ADODB.Recordset
Dim crReport1 As New crUnboundReport
Dim cnn1 As New ADODB.Connection
Dim strCnn As String
dim temp as string

sSQL = "Select Field1, Field2 From Table1"
strCnn = "Driver={SQL server};Server=lra_sql;Database=Project" 'write your own connection string

cnn1.Open strCnn
rs.Open sSQL, cnn1
crReport1.Database.AddADOCommand cnn1, rs.ActiveCommand
temp = "{ado." & rs.Fields(0).Name & "}"
crReport1.Text1.SetText (rs.Fields(0).Name)
crReport1.UnboundField1.SetUnboundFieldSource temp
temp = "{ado." & rs.Fields(1).Name & "}"
crReport1.Text2.SetText (rs.Fields(1).Name)
crReport1.UnboundString1.SetUnboundFieldSource "{ado.VisitName}"
crReport1.UnboundField2.SetUnboundFieldSource temp
crReport1.DiscardSavedData
'bind your own CRViewer
frmPreview.CRViewer1.ReportSource = crReport1
frmPreview.CRViewer1.ViewReport

frmPreview.Show


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top