SQL Server Performance

Retrieve data with code

Discussion in 'SQL Server 2005 Reporting Services' started by albertA, May 3, 2007.

  1. albertA New Member


    Is it possible to retrieve data from a database or dataset using CODE.
    If it is, what connection string should I use?

    I tried a Function similar to this:
    -----------------------------------------------------------------------------------
    Shared Function MyFuction (ByVal XNumber as String) as String

    Using connection as New SqlConnection(Data Source=SrvrName;Initial Catalog=DBName)
    connection.Open()

    Dim MyCMD as SqlCommand = New SqlCommand( _
    "(SELECT * FROM [TableName])",connection)
    End Using

    return MyCMD

    End Function
    -----------------------------------------------------------------------------------
    But I am getting an error: "SqlConnection" not defined.

    Is this the right way to connect?

    Any help will be appreciated.

    Thanks.
  2. satya Moderator

    http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=140294&SiteID=17 fyi and you are bit unclear that where you are trying to execute this function.

    Satya SKJ
    Microsoft SQL Server MVP
    Writer, Contributing Editor & Moderator
    http://www.SQL-Server-Performance.Com
    This posting is provided AS IS with no rights for the sake of knowledge sharing. The greatest discovery of my generation is that a human being can alter his life by altering his attitudes of mind.
  3. albertA New Member

    Thank You for responding.

    I am trying to execute it as Custom Code.
    I opened 'Report Properties'
    Clicked the 'Code tab' and pasted the code there.

    I tried: "Imports System.Data.SqlClient" at the top (as suggested by your link info).

    I also tried "Dim MyConnection As New System.Data.Sqlclient.SqlConnection(ConnectionString)"

    I get the error: 'Type System.Data.SqlClient is not defined'.

    Sorry, I am new to Reporting Services and that's why I am asking if it is possible to use ASP ar VB .NET code
    as Custom code in Reporting Properties to connect to a database or Dataset.

    I am not sure it can be done.

    Thanks again.
  4. albertA New Member

Share This Page