Calling a UDF from VB.NET

Posted on 2006-06-06
Last Modified: 2008-02-26
Does anybody have an example of code calling a SQL server User Defined Function from VB.NET?

Question by:hd181a
    LVL 69

    Assisted Solution

    by:Éric Moreau
    Hi hd181a,

    Is it a scalar-type UDF or a table-type UDF? It is exactly like retrieving data from a table or a view.

    select dbo.udfYourFunctionName

    table type:
    select * from dbo.udfYourFunctionName

    LVL 34

    Accepted Solution

    A udf can't be "called" direclty instead it should be used in a query.

    dim cmd as new sqlcommand
    dim oResult as object

    cmd.connection = mySQLConnection
    cmd.commandtext = "SELECT dbo.myUDF({some value})"  'you can parameterize this, use a variable, or just hardcode the value

       oResult = cmd.executescalar
    catch ex as exception (ex.message)
       if cmd.connection.state =
       end if
    end try

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    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…

    760 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

    12 Experts available now in Live!

    Get 1:1 Help Now