Dinakar Nethi

A .NET/SQL Server Blog

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

About Me

Links

Subscriptions

Article Categories



How to call a SQL Server UDF from ASP.NET

Here is a sample code to call a SQL Server UDF (User Defined Function) from ASP.NET

Sub GetNotes(contnum integer)
   Protected objCon As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
   Dim cmdtrans As SqlCommand,notes as string
   dim sqltrans as string ,popnotes as string
   sqltrans= "select dbo.fnpop_notes(@contnum)"
   cmdtrans=new sqlcommand(sqltrans,objCon)
   cmdtrans.Parameters.Add(New SQLParameter("@contnum",contnum))
   If objCon.State = 0 Then objCon.Open()
      notes=cmdtrans.ExecuteScalar()
   objCon.Close()
end sub

The code above is pretty much self xplanatory.

Based on a feedback I received from Richard O'Donnell I am adding a link to another article that tells you another ( better) way to do this. Heres the link : http://www.ftponline.com/vsm/2003_09_14th/online/hottips/rehak/

 

posted on Tuesday, April 27, 2004 11:12 AM by dinakar





Powered by Dot Net Junkies, by Telligent Systems