Calling a UDF from VB.NET

Posted on 2006-06-06
Medium Priority
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 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 total points
ID: 16842632
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

Brian Crowe earned 1000 total points
ID: 16842711
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
   messagebox.show (ex.message)
   if cmd.connection.state = connectionstate.open
   end if
end try

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 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