Implementing Managed code in SQL Server 2005 using Visual Studio.NET 2005 - Creating Managed Code using Visual Studio.NET 2005
(Page 3 of 5 )
Note: Before proceeding further, you need to create a database named "emp" in SQL Server 2005 using SQL Server Management Studio with a simple table "emp" as show in the following figure:

Open Start >> Programs >> Microsoft Visual Studio 2005 Beta >> Microsoft Visual Studio 2005
Using Visual Studio.NET 2005, proceed with following steps:
ImportsSystem
ImportsSystem.Data.Sql
ImportsSystem.Data.Sqlserver
ImportsSystem.Data.SqlTypes
PartialPublicClass UserDefinedFunctions
<SqlFunction()> _
PublicSharedFunction getEmployee(ByValEmpNoAsSqlString)AsSqlString
' Add your code here
DimcmdAsSqlCommand = SqlContext.GetCommand
cmd.CommandText = "SELECT ename FROM dbo.emp WHERE EmpNo='" & EmpNo.ToString & "'"
DimrecAsSqlDataRecord = cmd.ExecuteRow
Dimename AsString = rec.GetString(0)
Returnename
EndFunction
EndClass
Next: Executing the Managed Code from Visual Studio 2005 >>
More MS SQL Server Articles
More By Jagadish Chaterjee