|
-
May 13th, 2008, 06:15 AM
#1
Thread Starter
Member
[RESOLVED] Display Dataset !!!
HI all,
I have gone through a lot of post and read a lot of threads but i just can't get my problem solved. This might be an old question am putting back but pls can someone help me?
I've been trying some much things that am now getting a lil bit mixed up. What am looking for is a simple way to put some parameters or text box or whatever on a crystal report and then programmatically get a dataset and then bind it to the report to have the fields displayed on the report. Not using the wizard because i may change the query, so the dataset am finally getting is what i will bind to the report (no stored procedure used)
Thank you for your help.
WaZda
-
May 13th, 2008, 04:33 PM
#2
-
May 14th, 2008, 04:21 AM
#3
Thread Starter
Member
Re: Display Dataset !!!
Hi riteshjain1982,
and thank u very much for your post. My main concern is to be able to create the dataset programmatically (writing the code to connect to the DB, the query and all that and finally get the dataset), bind it to the Crystal Report and finally load it in a C.R. Viewer. Do you now see what am trying to do?
Any help will be highly appreciated.
-
May 14th, 2008, 07:12 AM
#4
Thread Starter
Member
Re: Display Dataset !!!
Hi All,
I've finally solve the problem. Here is how I did it, in case someone is have the same problem.
Create a Dataset and define the schema by drag and drop the database table from Server Explorer.
If there are multiple tables then put all the tables within one dataset itself.
Make sure the schema of your drag and drop TableFields on the Report is exactly the same schema of your query output. That is all to be done on the report.
Then u go write your vb.net codes in whatever form u r working.
Here is a sample of my code
Code:
'So to start this, i've dragged and dropped "CatId" and "CatType" from the dataset in the server explorer onto the CrystalReport2
Dim frmReportView As New Form1 'Form1 is where the form on which I have the Crytal Report Viewer
Dim myReport As New CrystalReport2 'CrystalReport2 is the report to generate
'Do the Connection to the Data base programmatically
Dim connectionstring As String = "Data Source=POSTE-91;Initial Catalog=MandatMission;Integrated Security=True"
Dim connection As New SqlClient.SqlConnection(connectionstring)
'Here is the Query String. On the Report I have only "CatId" and "CatType" so the query should be exactly the same therefore i select only "CatId" and "CatType"
Dim strSelectStatement As String = "SELECT CatId, CatType FROM CategPro where CatId = @CatId "
Dim SelectCommand As New SqlClient.SqlCommand(strSelectStatement, connection)
'Adding the parameter stated in the query. If u don't have any parameter in your query u shouldn't add the line below
SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@CatId", Trim$(txtCode1.Text)))
connection.Open()
'Create the Data Adapter
Dim da As New SqlClient.SqlDataAdapter(SelectCommand)
'Create the DataSet
Dim ds As DataSet = New DataSet
'Fill the DataSet with the Table from Which u are doing the Query
da.Fill(ds, "CategPro") 'Note here that the Table name is VERY IMPORTANT. It doesn't work with me when i don't add the "CategPro" as per what I have in the query string above named "strSelectStatement"
'Bind the DataSet to the Report
myReport.SetDataSource(ds)
'Load the Report in the Crystal Report Viewer
frmReportView.CrystalReportViewer1.ReportSource = myReport
'Close the Connection
connection.Close()
'Display the Report
frmReportView.ShowDialog(Me)
'Dispose the Report after the user has closed it
frmReportView.Dispose()
Hoping i've helped someone.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|