Retrieve data with code | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Retrieve data with code

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. 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
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.
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.

I found a way to do this.
For anybody interested, there are good instructions here: It’s not easy!, but it is possible. Al