locked
Basic SQL Data Loading Question RRS feed

  • Question

  • User1995131935 posted

    I am using Visual Studio 2010, creating a webite.  I am also using Crystal Reports 2010 to create a new, very basic report to display the raw data in one table called "MAPS".  The data comes for an SQL Database 2008 R2 Express and I am using VB.  I cannot figure out the code to load this data into my report.  Here is one of the many variations I have tried: 

     

    '***********************************

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim trpt As New StandardReport 'StandardReport is the StandardReport.rpt I created

    'Connection

    Dim sqlConn As New System.Data.SqlClient.SqlConnection

    sqlConn.ConnectionString =

    "Data Source=.\SQLEXPRESS;Initial Catalog=MAP_PROJECT;Integrated Security=True;"

    'Sql

    Dim tSQL As String = "Select * from Map;"

    Dim sqlComm As New System.Data.SqlClient.SqlCommand(tSQL, sqlConn) 'the sql command

    Dim ds As New StandardData 'StandardData is data object StandardData.xsd

    'Open Connection and get data

    sqlConn.Open()

    Dim TheDataAdapter As New SqlDataAdapter(tSQL, sqlConn)

    TheDataAdapter.Fill(ds,

    "Map")

    trpt.SetDataSource(TheDataAdapter)

    .

    CrystalReportViewer1.ReportSource = trpt

    End Sub

    ********************************

    Any help would be greatly appreciated!

    Thursday, September 13, 2012 2:23 PM

Answers

  • User1995131935 posted

    I finally got it.  Just a few simple lines of code but they are valuable.  So to others that are going through all of this, here it is for a simple report:

    *********************************

    Dim

    trpt As New StandardReport 'StandardReport is the StandardReport.rpt I created

    Dim iSql As String = "Select * from Map;"

    Dim sqlConn As New System.Data.SqlClient.SqlConnection

    sqlConn.ConnectionString =

    "Data Source=.\SQLEXPRESS;Initial Catalog=MAP_PROJECT;Integrated Security=True;"

    Dim dt As DataTable = New DataTable

    Dim da As New SqlDataAdapter(iSql, sqlConn)

    da.Fill(dt)

    trpt.SetDataSource(dt)

    CrystalReportViewer1.ReportSource = trpt

    CrystalReportViewer1.RefreshReport()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 13, 2012 3:38 PM