[英]Scalar Function SQL By Linq Vb.net
I have a Function in Sql For check if username and password is Correct return 1 or 0我在 Sql 中有一个 Function 检查用户名和密码是否正确返回 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
when call this function without Sql linq Return Real information当调用这个 function 没有 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
but when i need using linq return false always但是当我需要使用 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
This simple function can be used to get value from exactly one field one record query result这个简单的 function 可用于从一个字段一条记录查询结果中获取值
Public Function getDataScalar(ssql As String)
openConnection()
Try
Dim q As New MySqlCommand
q.Connection = db
q.CommandText = ssql
getDataScalar = q.ExecuteScalar
Catch ex As Exception
'Exception
End Try
End Function
How to use it:如何使用它:
Dim userid as String = getDataScalar("select username from user where userid=99")
Variable 'username' would be filled with the value of field username as a result from that query.作为该查询的结果,变量“用户名”将填充字段用户名的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.