arrr tsme again

coward

Member
Joined
Mar 23, 2003
Messages
13
Location
New Zealand
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:

Code:
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 ?
 
Are you using a DataReader?

you can do something like this...
Code:
        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
 
In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them.
 
Sorry,
I was responding to the same thing you were. Wife interupted me
while I was typing and you got there first.

Jon
 
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
 
Back
Top