
June 7th, 2002, 05:12 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
|
<i><b>Originally posted by : Kylua (colin@kylua.com)</b></i><br /><br /><br /><br />------------<br />Hugh (beginner) at 5/27/2002 2:43:22 PM<br /><br />I want to check a SQL database to see if a new UserID entered by a customer in a Web form textbox already exists and, if so, inform the customer to try again. Do I really have to use a DataAdapter and a DataSet to do this. It seems a lot of work just to retrieve and check for the existence of one value. Can anyone show me a simpler way, please?<br /><br />The following code is what I've used to check if a user is there when logging in. I've set up the connection, queried with a where username = clause and then if there are no records, the username aint there. The relevant check is starred:<br /><br />dbfile=Server.MapPath("da_data.mdb") <br /> Set OBJdbConnection=Server.CreateObject("ADODB.Connection")<br /> OBJdbConnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& dbfile & ";"<br />'OBJdbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile & ";" <br /><br /><br /> 'Set rs = Server.CreateObject("ADODB.Recordset")<br /> sql= "SELECT * FROM user Where Username = '" & Request.querystring("Username") & "'"<br /> response.write sql<br /> 'rs.Open sql, OBJdbConnection,3<br />Set rs = OBJdbConnection.Execute(SQL) <br /><br />'now we have the relevant data, let's check for a valid user/password<br /> *****if rs.eof then ***** response.redirect "No_user.asp"<br /> 'response.write rs.fields("password") & Request.querystring("Password")<br /> if rs.fields("password") <> Request.querystring("Password") then response.redirect "Wrong_Pass.asp"<br /><br />Not dead easy, but as easy as you're going to get.<br />(I think)<br /> <br /><br />
|