Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

well after some playing I had my app going real good and all - but with a ty access database that I had as a test db.

 

I have got it going with my other db now tho that is real :D

 

now the problem is that my recordset has 2 fields

 

both appear empty.

 

code snippet:

 

command = "SELECT user_name,user_password FROM users WHERE user_name='" & txtUsername.Text & "' AND user_password=PASSWORD('" & txtPassword.Text & "')"

recset = myconn.Execute(command)

               MsgBox(recset.Fields.Count)

               userName = recset.Fields.Item("user_name").Value
               userPass = recset.Fields.Item("user_password").Value

 

so the initial command works fine if the record is returned with both username and password. if either field is empty i do a test for that and it throws its toys. BUT if one field is right and the other is wrong it causes an exception at "userName =" - of course because the recset is effectively empty, well the fields are - recset.fields.count returns 2 so there are the 2 fields in it.

 

any help :D?

 

an alternate way would kick , but this seems to be the easiest, perhaps best way (most secure). so yeah ideas ?

  • Moderators
Posted

Are you using a DataReader?

 

you can do something like this...

       Dim dr As SqlDataReader
       Dim cmd As SqlCommand
       Dim con As New SqlConnection(YOUR_connString)
Dim sSql As String = "SELECT user_name,user_password FROM users " & _
			"WHERE user_name='" & _
			txtUsername.Text & "' AND " & _
			"user_password=PASSWORD('" & txtPassword.Text & "')"

       Try
           If con.State = ConnectionState.Closed Then con.Open()
           cmd = New SqlCommand(sSql, con)
           dr = cmd.ExecuteReader
           While dr.Read	
                 userName = dr.Fields.Item("user_name").Value
                 userPass = dr.Fields.Item("user_password").Value
           End While
           Return False
       Catch
           Return False
       Finally
           If Not con.State = ConnectionState.Closed Then con.Close()
           If Not dr.IsClosed Then dr.Close()
           If Not cmd Is Nothing Then cmd.Dispose()
       End Try

Visit...Bassic Software
  • *Experts*
Posted

Robby,

You been following the "Bugger me..." thread by Mothra?

Take a look if you have time.

I think I found the problem but.... could use an experienced hand.

 

Jon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...