【发布时间】:2009-06-05 21:05:08
【问题描述】:
这是一个简单的函数,如果用户存在于 users 表中则返回 TRUE,否则返回 false。
由于某种原因它总是返回 false,我什至删除了 WHERE 子句,我仍然得到 false? (查询分析器中的手动检查告诉我我有很多行?)
Public Shared Function DoesUserExist(ByVal userID As Integer) As Boolean
Dim retValue As Boolean
retValue = False
Using conn As New SqlConnection(GetConnectionString())
'Dim cmd As SqlCommand = New SqlCommand("SELECT user_ID FROM users WHERE user_ID = @userID", conn)
Dim cmd As SqlCommand = New SqlCommand("SELECT user_ID FROM users", conn)
cmd.Parameters.Add("@userID", SqlDbType.NVarChar).Value = userID
cmd.CommandType = CommandType.Text
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
'If Not reader Is Nothing Then
' HttpContext.Current.Response.Write("<br>Null")
'End If
If reader.Read() Then
retValue = True
End If
conn.Close()
cmd.Dispose()
End Using
retValue = False
Return retValue
End Function
【问题讨论】:
标签: sql-server vb.net ado.net