Database row

Results 1 to 5 of 5

Thread: Database row

  1. #1
    Join Date
    Dec 1969

    Default Database row

    I want an IF statement to check if a value is in any row of a database. And if it is do something. Can someone show me the how. People are telling me how but not showing. Please help.<BR>Thanks

  2. #2
    KPW Guest

    Default RE: Database row

    They&#039re telling instead of showing because they figure you won&#039t learn anything if they just show you. While I agree with that philosophy somewhat, I also know that I sometimes need to see something done and learn from that.<BR><BR>Anyhoo, I&#039m not sure if this will do it, but I think you need to use a SELECT statement to pull all records that contain the value you are looking for, then just check quickly to see if you got back any records.<BR><BR>&#060;%<BR><BR>Dim objRS<BR>Dim sSql<BR><BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR><BR>sSql = "SELECT * FROM tMyTable WHERE field LIKE &#039%myValue%&#039"<BR><BR>objRS.Open sSql, myDataSource<BR><BR>If Not objRS.EOF and Not objRS.BOF then<BR>&#039 found some records containing the value<BR>End If<BR><BR>objRS.Close<BR>Set objRS = Nothing<BR>%&#062;<BR><BR>That&#039s how I would probably do it, anyway. I&#039m not saying it&#039s the best.<BR><BR>HTH

  3. #3
    Bobo Flinstone Guest

    Default RE: Database row

    could i also use this to have a form decide whther or not a username has been taken for a signup thing?

  4. #4
    KPW Guest

    Default RE: Database row

    You mean like if you are signing up for some sort of online account and someone else has already taken your desired user name?<BR><BR>Absolutely. Just check the desired user name against your DB username field. If you get a record back, then someone else has already taken that user name.

  5. #5
    Bobo Flinstone Guest

    Default RE: Database row

    ok cool, but how would i implement it? and also i am getting errors and have the feeling that i did something wrong, hehe.<BR><BR>here&#039s the latest error:<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039 80004005&#039 <BR><BR>[Microsoft][ODBC Driver Manager] Data source name too long <BR><BR>Here&#039s my script:<BR><BR>&#060;%<BR> Dim sSql<BR> <BR> Set Conn = Server.CreateObject("ADODB.Connection")<BR><BR> sSql = "SELECT * FROM data WHERE Username LIKE strUsername"<BR> <BR> Conn.Open sSql, loginpass<BR> <BR> If Not objRS.EOF and Not objRS.BOF then<BR> flgContentOK = True<BR> flgSuccess = True <BR> Else<BR> Reponse.Redirect "nametaken.asp"<BR> End If<BR><BR> objRS.Close<BR> Set objRS = Nothing<BR>%&#062;<BR><BR>but before i used this script, i had another script (same .asp page) and it already opened the database using Conn.Open but it closed the database within the same set of &#060;%%&#062;&#039s. I put in the script you provided withiin its own set of &#060;%%&#062;&#039s and just got errors. should i close the source AFTER using this code or what?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts