我将osian文本作为sqlparameter的值传递给asp.net/vb.net中的参数化查询
但返回没有行 - 我在ssms中运行的相同查询 - 给出结果行。不要明白错误在哪里。
数据库已经整理了' Persian_100_ci_ai
Vb.net:
Dim cmd As New SqlCommand
Dim dt As New DataTable
Dim dr As SqlDataReader
dt.TableName = "temp"
Try
If Not conn.State = ConnectionState.Closed Then conn.Close()
If conn.State = ConnectionState.Closed Then conn.Open()
cmd.Connection = conn
Dim qry As String = "Select * from users WHERE [Name]=@UserName AND [Pwd]=@Password"
cmd.commandtext = qry
cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50).Value = "ادمین"
cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 50).Value = "ادمین"
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
dt.Load(dr)
End If
Return dt
Catch ex As Exception
Return Nothing
Finally
dt = Nothing
cmd.Connection = Nothing
cmd.Parameters.Clear()
cmd.Dispose()
End Try
在ssms中:
declare @UserName nvarchar(50) = 'ادمين'
declare @Password nvarchar(50)= 'ادمين'
select * from Users where [name]=@UserName and [Pwd] = @Password
在vb.net中有趣的部分我创建了查询嵌入标准而没有作为参数传递 - 它有效:
Dim cmd As New SqlCommand
Dim dt As New DataTable
Dim dr As SqlDataReader
Dim pLoginName As String = "ادمین"
Dim pPassword As String = "ادمین"
dt.TableName = "temp"
Try
If Not conn.State = ConnectionState.Closed Then conn.Close()
If conn.State = ConnectionState.Closed Then conn.Open()
cmd.Connection = conn
Dim qry As String ="Select * from users WHERE [Name]='" & pLoginName & "' AND [Pwd]='" & pPassword & "'"
cmd.CommandText = qry
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
dt.Load(dr)
End If
Return dt
Catch ex As Exception
Return Nothing
Finally
dt = Nothing
cmd.Connection = Nothing
cmd.Parameters.Clear()
cmd.Dispose()
End Try