Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - DB query
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

DB query

 Post Reply Post Reply Page  <12
Author
IrishNewbie View Drop Down
Newbie
Newbie


Joined: 06 November 2003
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote IrishNewbie Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2003 at 9:26am

I haven't been doing ASP.NET as lons as others on this board, I got landed with a project which has to be done and I've worked out how to let people register on the site but its when i try using SELECT that I run into trouble, I've been pissing around with a login page for over a week now and getting nowhere.

I obviously forgot these parts of the code:

'Initialize the database command
 

     aQuery = "SELECT Pword FROM Students WHERE StudentID = " & intID & ""
  aCommand.Connection = aConnection
  aCommand = New OleDbCommand(aQuery, aConnection)
  aCommand.ExecuteNonQuery()
 

 Try

    DbReader = aCommand.ExecuteReader()
    While DbReader.Read
  If (strPassword = ???????????????)


       LoginSucces = True
  End If
    End While
    DbReader.Close

 Catch

   LoginSucces = False

 End Try

 aConnection.Close()

Am i heading in the right direction at all with that much?

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2003 at 11:06am

That looks like my code! Except you modified it a bit to heavy. Anyway, you could try this:

Public Function Login(strId As Integer, strPassword As String)

Dim DbConnection As New OleDbConnection, DbCommand As New OleDbCommand, DbReader As OleDbDataReader, LogginSucces As Boolean

     With DbConnection

           .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\DB\records.mdb"
          'Open the connection
           .Open()

     End With

     'Initialize the database command

     With DbCommand

         .CommandText = "SELECT * FROM Students WHERE StudentID = " & strId & "' And Pword = '" & strPassword & "'"
         .Conne ction = DbConnection

     End With

 Try

    DbReader = aCommand.ExecuteReader()
    While DbReader.Read

       LoginSuccesfull = True

    End While
    DbReader.Close()

 Catch

   LogginSucces = False

 End Try

 DbConnection.Close()

End Function

Gone..
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2003 at 11:19am

Originally posted by IrishNewbie IrishNewbie wrote:


Am i heading in the right direction at all with that much?

theres a better way, and there's all sorts of holes in your code

1) First off.. with your SQL statement.. how are you supposed to know what Password to get if the person isn't logged in to provide your code with what "StudentID" we are using
2) What about checking the username??
3) How are you planning on having the code "remember" that the person entered the right password?

I mean see, those three questions have absolutely zip to do with exact coding, this whole project of your hasn't been thought out on single bit judging by what you have posted.... you are so unprepared.....  maybe you take that constructive criticism as "me being a prick", but as long as you realize that you really need to do some research and learn some basics before taking on something so incredibly far over your head...... it appears you just copied and pasted some code w/o having even the slighest clue on what it does or is used for.... that's never ever going to result in success

anyways.. alternative code following along with this excellent data access article from 4guysfromrolla

Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myDataReader As OleDbDataReader

Dim aQuery As String
aQuery = "SELECT StudentID, Uname FROM Students WHERE Pword = '" & Replace(strPassword,"'","''") & "' AND Uname = '" & Replace(strUsername,"'","''") & "'"
myConnection = New OleDbConnection(aConnection)
myConnection.Open()
myCommand = New OleDbCommand(aQuery, myConnection )
myDataReader = myCommand.ExecuteReader()
If myDataReader.HasRows() then
    'Login Good, we have rows returned that matched
    While myDataReader.Read()
        'maybe store the Uname and StudentID in session variables or something
    End While
else
    'Login Bad since we have no rows
End if
myDataReader.Close()
myConnection.Close

you can take my criticism/help or leave it, i am not here to make friends or do anyone else's work for them, i'm here to help with code :)  but what you are after right now is not code, its getting a clue on what the heck you are doing from a much higher level

Contribute to the working anarchy we fondly call the Internet
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2003 at 2:45pm

You should add the

Try
Catch
End Try

in the proces, since the app will fail when the table doesn't returns something.

Gone..
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2003 at 3:15pm
the ".HasRows" property is basically a "do i have returned rows" check, the try...catch block is not necessary.....  and in the case of wrapping database calls is probably undesired since that'll mask/hide what a database error would be if it happens...
Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.