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
declare @UserName nvarchar(50) = 'ادمين' declare @Password nvarchar(50)= 'ادمين' select * from Users where [name]=@UserName and [Pwd] = @Password
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
cmd.Parameters.AddWithValue("@UserName", "ادمین")
dt = Nothing
Finally
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)