coward Posted April 1, 2003 Posted April 1, 2003 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 ? Quote
Moderators Robby Posted April 1, 2003 Moderators Posted April 1, 2003 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 Quote Visit...Bassic Software
coward Posted April 1, 2003 Author Posted April 1, 2003 mmm i was using a recordset... i guess a datareader is next on the list of things to try :) Quote
Moderators Robby Posted April 1, 2003 Moderators Posted April 1, 2003 A recorset in .net ? Is that a new feature? Quote Visit...Bassic Software
*Experts* jfackler Posted April 1, 2003 *Experts* Posted April 1, 2003 In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them. Quote
Moderators Robby Posted April 1, 2003 Moderators Posted April 1, 2003 jfackler, I was being sarcastic. Quote Visit...Bassic Software
*Experts* jfackler Posted April 1, 2003 *Experts* Posted April 1, 2003 Sorry, I was responding to the same thing you were. Wife interupted me while I was typing and you got there first. Jon Quote
*Experts* jfackler Posted April 1, 2003 *Experts* Posted April 1, 2003 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 Quote
coward Posted April 2, 2003 Author Posted April 2, 2003 A recorset in .net ? Is that a new feature? just following some tutorials i found :p so im a n00b, gimme a break ;) Quote
a_jam_sandwich Posted April 2, 2003 Posted April 2, 2003 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=69746 Have a read of this show shine some light Andy Quote Code today gone tomorrow!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.