即使有数据,Guid也会返回空白

时间:2012-03-09 10:27:59

标签: vb.net

我有一个非常奇怪的问题。我有一个vb.net系统,我在SQl 2005 express中将我的主键ID存储为uniqueidentifier。我有这个功能,一直在努力,但突然停止工作。当我执行该函数时,它返回一个空的Guid,尽管它们是数据库中的数据并且查询是正确的。

Public Function GetWSB_GUID(ByVal MyWSBID As String) As Guid
    Dim MyWSB_GUID As Guid
    Dim My_sqlCommand As SqlClient.SqlCommand
    My_sqlCommand = New SqlClient.SqlCommand("select WSB_UID from WSBGeneral where WSBID='" & MyWSBID & "'", Conn)
    If My_sqlCommand.Connection.State = ConnectionState.Closed Then
        My_sqlCommand.Connection.Open()
    End If
    MyWSB_GUID = My_sqlCommand.ExecuteScalar

    Return MyWSB_GUID

End Function

当我更改函数以将WSB_UID作为字符串返回时,它可以正常工作。这是适用的字符串版本

Public Function GetWSB_GUID(ByVal MyWSBID As String) As String
    Dim MyWSB_GUID As String
    Dim My_sqlCommand As New SqlClient.SqlCommand

    My_sqlCommand = New SqlClient.SqlCommand("select WSB_UID from WSBGeneral where WSBID='" & MyWSBID & "'", Conn)
    If My_sqlCommand.Connection.State = ConnectionState.Closed Then
        My_sqlCommand.Connection.Open()
    End If
    MyWSB_GUID = Convert.ToString(My_sqlCommand.ExecuteScalar)

    Return MyWSB_GUID
End Function

可能是什么问题?说实话,我迷失了,因为直到一天前它一直在努力。

0 个答案:

没有答案
相关问题