Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SSRS Custom Code to read from database

Avatar of JEClark
JEClarkFlag for United States of America asked on
Microsoft SQL Server 2008
5 Comments1 Solution1552 ViewsLast Modified:
Is there anything obviously incorrect in what I am doing, below?  Any help would be most appreciated.

I am using Northwind database and working on a proof-of-concept.  I have added references to the System.Data and System.XML assemblies using Report-Report Properties-References and have a report with three columnq - CompanyName, ContactName and CustomerOrderCount.  

I am atempting to use custom code in SSRS 2008 to extract CustomerOrderCount (Expression"=Code.GetCustomerOrderCount(Fields!CustomerID.Value") by calling the following code/function which I copied from http://www.devx.com/codemag/Article/33656/1954 in the Report-Report Properties-Code box, but I receive only "#Error" in the CustomerOrderCount:

 Function GetCustomerOrderCount(ByVal CustomerID As String) As Integer
        Dim oConn As New System.Data.SqlClient.SqlConnection

        oConn.ConnectionString = "Data Source=MyServer;Initial Catalog=Northwind;Integrated Security=SSPI;"

        Dim oCmd As New System.Data.SqlClient.SqlCommand
        oCmd.Connection = oConn
        oCmd.CommandText = "Select count(*) From Orders Where CustomerID = @CustomerID"
        oCmd.Parameters.AddWithValue("@CustomerID", CustomerID)
        Dim nRetVal As Integer = oCmd.ExecuteScalar()
        Return nRetVal
        End Function
Avatar of JEClark
JEClarkFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers