我在sql中有一个检查用户名和密码是否正确的函数,返回1或0
CREATE Function [dbo].[checklogin](@user varchar(30),@pass varchar(30))
Returns BIT
AS
BEGIN
DECLARE @check as bit
if (SELECT count(*) from dbo.Users where dbo.USERS.user_name= @user and dbo.USERS.user_password=@pass)=1
set @check = 1
else
set @check=0
Return @check
END
在没有sql的情况下调用此函数时,linq返回实际信息
Sub loginCheck(ByVal username As String, ByVal password As String, ByVal frm As Form)
Using con As New SqlConnection(inform.connectionstring)//
con.Open()
Using cmd As New SqlCommand("select dbo.checklogin('Manager','123');", con)
Dim a As Boolean = CBool(cmd.ExecuteScalar)
If a Then
MsgBox("Success")
Else
MsgBox("Failed")
End If
End Using
End Using
End Sub
但是当我需要使用linq时,总是返回false
Sub loginCheck(ByVal username As String, ByVal password As String, ByVal frm As Form)
Using con As New SqlConnection(inform.connectionstring)
con.Open()
Dim dta As New DataAj
Dim ab As Boolean = dta.checklogin(username, password).Value
If ab Then
MsgBox("Success")
Else
MsgBox("Failed")
End If
End Using
End Sub
1条答案
按热度按时间0md85ypi1#
这个简单的函数可以用来从一个字段和一个记录查询结果中获取值
如何使用:
变量'username'将由该查询的结果字段username的值填充。