Link to home
Create AccountLog in
Avatar of trims30
trims30

asked on

VS2008 Reports

Need assistance writing my first report in VS2008 (VB.Net) Winforms.
Am new to this environment and don't know how to begin creating a report.

I have a database and am using SQLServer2012 and there are no compatible drivers for SqlServer2012 available for VS2008 to my knowledge so I can't use the ReportViewer Wizards to access my database.

Code below is what I'm using to create a DataTable.  "MyData"

I would like to get a report showing the 5 columns for each row.

Any help would be appreciated - Got to learn this stuff!

Tools I have are whatever comes with VS2008 MsReportViewer, CrystalReportViewer, CrystalReportDocument.


Lee


Imports System.Data.SqlClient
Imports System.Data.DataTable
Public Class Form1
    Dim Conn As SqlConnection
    Dim myCommand As New SqlCommand
    Dim myAdapter As New SqlDataAdapter
    Dim myData As New DataTable
    Dim sql As String
    Dim myConnString As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Conn = New SqlConnection()        'Set New Instance of Sql Connection
        myConnString = "Data Source=LEE-PC;" & _
        "Initial Catalog=TRIMS_SQL_Data_2012;" & _
        "Integrated Security=True"

        Conn.ConnectionString = myConnString

        Try
            Conn.Open()                     'Open Connection
        Catch myerror As SqlException
            MessageBox.Show("Error connecting to the database: " & myerror.Message)
        End Try

        sql = "SELECT * FROM Budget_Transactions WHERE Trans_ID > 30 ORDER BY Trans_ID"
        Try
            myCommand.Connection = Conn                     'pass connection to Command Object
            myCommand.CommandText = sql                     'pass Sql command 
            myData.Clear()

            myAdapter.SelectCommand = myCommand             'assign command to Data Adaptor
            myAdapter.Fill(myData)

        Catch myerror As SqlException
            MsgBox("There was an error reading from the database: " & myerror.Message)
        End Try

    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of trims30
trims30

ASKER

Excellent article - Got it working - had some difficulty creating dataset from Schema but got past it.

Now to do it again and document what I did.

Thanks.

Lee