call SqlServer scalar function from .NET

Posted on 2006-05-15
Last Modified: 2012-08-13

I know how to call stored procedures from VB.NET, but is there a way to call Scalar Functions from .NET code? WOuld this work, even though I am calling a function and not a procedure?

            Dim cn As New SqlConnection("server=.\ddb;database=SFS;integrated security = true")

            Dim cmd As New SqlCommand("monthsForPivot", cn)
            'Dim cmd As New SqlCommand("make_fundingNew_05_dynamic_grossCenter", cn)
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.AddWithValue("@endMonth", "200512")
            cmd.Parameters.AddWithValue("@format", "MTH")

Question by:brokeMyLegBiking
    LVL 69

    Accepted Solution

    Call it using a SQL Select statement:

    select dbo.make_fundingNew_05_dynamic_grossCenter(200512, 'MTH')
    LVL 4

    Author Comment

    ha! very simple, very good.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now