Creating a report from existing Dataset

GaWill

Member
Joined
Feb 16, 2006
Messages
13
Location
South Wales
Programming Experience
Beginner
Hi

I have already created a datagrid in my vb2005 application that displays the data i need it to using a sqlclient connection and sql querys. However, i now want to export this information that i have been loading into a datagrid to a crystal report. How do i go about doing this a crystal reports doesnt find my datasource in the wizard as my connection has been created in code as below.

VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] cs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection([/SIZE][SIZE=2][COLOR=#800000]"Server=myserver;Database=shire;User ID=user;Password=pass;Trusted_Connection=False"[/COLOR][/SIZE][SIZE=2])
[/SIZE] 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Adapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlDataAdapter
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ds [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE]

So the ds dataset you see there already has the data i want loaded into, i just need to export this to a crystal report ?

Any pointer would be a great help as i havent used reports before.
 
Please somebody ? Ive added some more code to help.

Hi
i have already created a datagrid in my vb2005 application that displays the data i need it to using a sqlclient connection and sql querys. However, i now want to export this information that i have been loading into a datagrid to a crystal report. How do i go about doing this as crystal reports doesnt find my datasource in the database expert wizard as my connection has been created using code as below and not using the wizards. As my connection is made when i populate the datagrid it is not shown as a datasource in the server explore etc so i cant figure out how to get crystal reports to view my data for me to pull fields onto the report ?

VB.NET:
Public Class Form1

    'Declarations
    Dim cs As New SqlClient.SqlConnection("Server=myserver;Database=shiredata;User ID=user;Password=pass;Trusted_Connection=False")
    Dim Adapter As New SqlClient.SqlDataAdapter
    Dim ds As New DataSet
    Dim SearchDateText As Date


    'SQL Query
    Dim strSQL As String = "SELECT " & _
   "dbo.CLINIC.CLINICNO, " & _
   "dbo.CLINIC.BOOKED_DATE, " & _
   "dbo.CLINIC.BOOKED_TIME, " & _
   "dbo.STAFF.NAME, " & _
    "dbo.PATIENT.PEDNO, " & _
   "dbo.PATIENT.REGNO, " & _
   "dbo.PATIENT.FIRSTNAME + ' ' + dbo.PATIENT.LASTNAME AS PatName, " & _
   "dbo.PATIENT.DOB " & _
    "FROM (" & _
   "dbo.CLINIC INNER JOIN dbo.PATIENT ON dbo.CLINIC.INTID = dbo.PATIENT.INTID" & _
   ") INNER JOIN dbo.STAFF ON dbo.CLINIC.STAFF_CODE_1 = dbo.STAFF.STAFF_CODE " & _
   "WHERE (((dbo.CLINIC.COMPLETE)='booked'AND BOOKED_DATE = @BOOKED_DATE ))"


    'Calls SQL Query and Links to Connection
    Dim cmd As New SqlClient.SqlCommand(strSQL, cs)


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Sets TextBox Entry to SearchDateText Variable
        SearchDateText = Me.txtDate.Text

        'Creates Booked_date parameter to be passed to sql statement and sets its value to SearchDateText
        cmd.Parameters.Add("@BOOKED_DATE", SqlDbType.DateTime, 10, "BOOKED_DATE").Value = SearchDateText

        'Calls the SQL Command
        Adapter.SelectCommand = cmd

        'Shows Number of Records Being Found
        Dim i As Integer
        i = Adapter.Fill(ds)
So the ds dataset you see there already has the data i want loaded in to it, i just need to export these filtered fields to a crystal report ?

Any pointers would be a great help as i havent used reports before.
 
Back
Top