Re: check username and password in database



Hey,

I have the errors worked out except for:
Command.Connection = MyConnectionObject

I get the error:

'MyConnectionObject' is not declared.



I tried putting in the name of the data set in place of Myconnectionobject
but that didn't work either. any help would be greatly appreciated!

Thanks,

Kevin





"Spam Catcher" <spamhoneypot@xxxxxxxxxx> wrote in message
news:Xns984AAA0C02FA8usenethoneypotrogers@xxxxxxxxxxxx
"Kevin O'Brien" <kobrien@xxxxxxxx> wrote in
news:Oli5KJa4GHA.3604@xxxxxxxxxxxxxxxxxxxx:

So you are saying I should created 2 unbound textboxes to prompt for
username and password and name the textboxes UserName and Password?
Then I can run this SQL select statement right from my VB code?

Exactly ; )


To query the DB, you can do:

Dim Command As New SqlClient.SqlCommand
Command.Connection = MyConnectionObject
Command.CommandText = "SELECT COUNT(1) FROM TABLE WHERE UserName =
@UserName AND Password = @Password"

Command.Parameters.Add(New SqlClient.SqlParameter("@UserName",
txtUserName.text))
Command.Parameters.Add(New SqlClient.SqlParameter("@UserName",
txtPassword.text))

'If count > 0 means username + password matched
If Command.ExecuteScalar > 0 Then
MsgBox("Successful Login")
Else
MsgBox("Try Again")
End If


.