Select statement-True or false?

mmarkym

Member
Joined
Aug 20, 2005
Messages
13
Programming Experience
3-5
I have this function with a Select statement. After the select statement I want to dtermine if the select statement was successful or not and if successful to redirect to a page.

Also is the syntax of the select statement correct?



Public Function Login(ByVal user, ByVal Pass) As String
cn.ConnectionString = "integrated security=true;data source='mark\netsdk';persist security info=False;initial catalog=Login"
cn.Open()

Try

Dim cmd As New SqlCommand
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM Register WHERE Username = user and Password = pass"


Catch ex As Exception
MsgBox(ex.Message)
Finally
cn.Close()
End Try
End Function
 
well, for starters, you will need to execute your statement.
Secondly, you can set a flag in your try (after the execute) that indicated success, and set the flag in the Catch to indicate failure... then after the try...catch check the flag.

Lastly your command text is wrong too....
VB.NET:
cmd.CommandText = "SELECT * FROM Register WHERE Username = '" & user & "' and Password = '" & pass & "'"

-tg
 
NEVER WRITE SQL LIKE THAT!

Always use parameters:
VB.NET:
cmd.CommandText = "SELECT * FROM Register WHERE Username = @Username and Password = @Password"
cmd.Paramters.Add("@Username", sqldbtype.varchar, 50).Value = user
cmd.Paramters.Add("@Password", sqldbtype.varchar, 50).Value = pass
 
Yeah, what Schenz said.... use parameters....

I'll take my two lumps now....

-tg
 
Back
Top