using a dataset/datatable as input for a crystal report

B

Bernie Yaeger

I have written numerous crystal reports and connected them to sql tables and
stored procedures. But evidently you can bind a report to a
dataset/datatable as the datasource. Can anyone show me some simple code
that does this? Also, when I open cr 9, where would I go to assign a
dataset as its datasource?

Thanks for any help.

Bernie Yaeger
 
J

JH

the following code can establish connection to database, create dataset and
run a your crystal report. It worked fine with my project here.


'establish connection to the database
Dim myconnection As New OleDb.OleDbConnection

myconnection.ConnectionString = _

"Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=C:\temp\demo.mdb;" & _

"User ID=Admin;" & _

"Password="

Dim Mycommand As New OleDb.OleDbCommand

Mycommand.Connection = myconnection

Mycommand.CommandText = "select * from archlog1 where File_type = '" & FType
& "'"

Mycommand.CommandType = CommandType.Text

Dim MyDA As New OleDb.OleDbDataAdapter

MyDA.SelectCommand = Mycommand

Dim myDS As New DataSet

MyDA.Fill(myDS, "archlog1")

'connecting it to the report rpt designed in crystal reports


Dim rpt As New Input1

rpt.SetDataSource(myDS)

CrystalReportViewer1.ReportSource = rpt



Try it and hope it is what you are looking for.

Yonas
 
J

JH

P.S. Modify the select statement to fit your needs. I just pasted what I had
in my query.

Again
Yonas
 
B

Bernie Yaeger

Hi Yonas,

Thanks so much - this gets me on the way to the solution I need.

Tx,

Bernie
 
A

Ayaz Ahmed

Hello,

strsql = "Select G_R_Number,Student_Name from Students Order by
G_R_Number"
objrs.Open strsql, objconn
Do Until objrs.EOF
cmbstudentname.AddItem objrs("Student_Name")
cmbstudentnic.AddItem objrs("G_R_Number")
objrs.MoveNext
Loop
objrs.Close
Set objrs = Nothing


If cmbstudentname.Text = "" And cmbstudentnic.Text = "" Then
MsgBox "Cannot generate Report. No field for Student's
Information has been selected.", vbInformation, "Alert"
Cancel = True
ElseIf cmbstudentname <> "" Then

pathNAme = App.Path & "\report_student.rpt"
CRsearch.ReportFileName = pathNAme
CRsearch.SelectionFormula = "{Students.Student_Name}='" &
cmbstudentname.Text & "'"
CRsearch.Action = True
ElseIf cmbstudentnic <> "" Then

pathNAme = App.Path & "\report_student.rpt"
CRsearch.ReportFileName = pathNAme
CRsearch.SelectionFormula = "{Students.G_R_Number}=" &
cmbstudentnic.Text
CRsearch.Action = True
End If


Thanks,


Warm Regards,

Ayaz Ahmed
Software Engineer & Web Developer
Creative Chaos (Pvt.) Ltd.
"Managing Your Digital Risk"
http://www.csquareonline.com
Karachi, Pakistan
Mobile +92 300 2280950
Office +92 21 455 2414
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top