我是 CLR 新手的 SQL/VB 人员。基本上,我想创建一个 SQL 函数来传递一个 ID 参数,并从 SQL 表中返回相应的数据;
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Partial Public Class UserDefinedFunctions
<Microsoft.SqlServer.Server.SqlFunction(DataAccess:= DataAccessKind.Read)> _
Public Shared Function FalloutProfile(ByVal CRFNID As Integer) As SqlString
Using connection As New SqlConnection("context connection=true")
connection.Open()
Dim command As New SqlCommand("SELECT RATE0ORIG FROM dbo.clsgfunc WHERE CRFNID=@pnum", connection)
command.Parameters.Add("@pnum", SqlDbType.SmallInt).Value = CRFNID
Dim reader As SqlDataReader
reader = command.ExecuteReader()
SqlContext.Pipe.Send(reader)
End Using
End Function
End Class
我似乎无法正常工作:
System.NullReferenceException:对象引用未设置为对象的实例。
有任何想法吗?