ASP DB

Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: ASP DB

  1. #1
    Mezaache Guest

    Default ASP DB

    I have a form where a user enter his social security number it dispalys his information from an access db, I want to give a choice to the user to enter a ssn with a dash between numbers or just a number without dashes(number-number- or hall number)<BR>please do you have an idea ?<BR>My case is working only with dash between number, I wanted to validate both.<BR>Thanks

  2. #2
    Join Date
    Dec 1969
    Posts
    1,019

    Default RE: ASP DB

    How about letting the user enter whatever they want, dashes or no dashes? Then you just strip the dashes out before using the value against the database.<BR>Here&#039s an example I used a while ago - it&#039s a bit longish, I&#039m sure you could whittle it down.<BR>dim ps(6)<BR>ps(0)=request.form("ssn")<BR>ps(0)=Trim(p s(0))<BR>ps(1)=len(ps(0))<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR> for a=1 to ps(1)<BR> if InStr(1,ps(0),"-")&#060;>0 then<BR> ps(4)=ps(4)+1<BR> ps(3)=""<BR> ps(3)=InStr(1,ps(0),"-")<BR> ps(2)=ps(2) & Mid(ps(0),1,(ps(3)-1))<BR> ps(0)=Mid(ps(0),(ps(3)+1))<BR> else<BR> if len(ps(2))&#060;>(ps(1)-ps(4)) then<BR> ps(2)=ps(2) & ps(0)<BR> end if<BR> Exit For<BR> end if<BR> next<BR> set a=nothing<BR> else<BR> ps(2)=request.form("ssn")<BR>end if

  3. #3
    Mezaache Guest

    Default RE: ASP DB (Leo)

    DIDN&#039T WORK<BR>I didn&#039t understand the script.<BR>thanks

  4. #4
    Join Date
    Dec 1969
    Posts
    1,019

    Default RE: ASP DB

    Make sure you&#039re running this server side. I changed it a little to make it clearer. I&#039ll break this down a little:<BR>&#060;% dim ps(6)<BR>&#039declare an array<BR> ps(0)=request.form("ssn")<BR>&#039set ps(0) to the input field you want to strip dashes from.<BR>&#039Use whatever you called the input field on your form<BR> ps(0)=Trim(ps(0))<BR>&#039trim leading and training spaces<BR> ps(1)=len(ps(0))<BR>&#039this is the length of the input received<BR> if InStr(1,ps(0),"-")&#060;>0 then<BR>&#039test to make sure there are dashes before doing all this<BR>&#039processing. <BR> for a=1 to ps(1)<BR>&#039your going to check the entire string for dashes, so<BR>&#039you&#039ll go from 1 to the length<BR> if InStr(1,ps(0),"-")&#060;>0 then<BR>&#039again, check for dashes <BR> ps(4)=ps(4)+1<BR>&#039this tracks the amount you&#039ve trimmed from the string<BR> ps(3)=InStr(1,ps(0),"-")<BR>&#039this sets the position of the dash<BR> ps(2)=ps(2) & Mid(ps(0),1,(ps(3)-1))<BR>&#039ps(2) holds the dashless ssn. Since this is a loop, you<BR>&#039may already have some dashless ssn. You&#039re going to<BR>&#039add to what you have by taking the taking the ssn string from &#039the first - character to ps(3), the location of the first - using the Mid &#039function<BR> ps(0)=Mid(ps(0),(ps(3)+1))<BR>&#039now that you&#039ve stripped the -,you want to reduce the original <BR>&#039string. Use the Mid function to strip away what you are already<BR>&#039holding in ps(2) plus one character for the dash itself<BR> else<BR>&#039This is the else for the test for dashes<BR> ps(2)=ps(2) & ps(0)<BR>&#039this adds any remaining chars to your dashless string <BR> Exit For<BR>&#039if there are no more dashes, exit the loop. Why keep processing?<BR> end if<BR> next<BR> set a=nothing<BR> else<BR> ps(2)=request.form("ssn")<BR>&#039this is the else from the original test for dashes.It is &#039possible there are no dashes at all, so you make ps(2) equal<BR>&#039to the originally supplied string<BR> end if<BR>&#037;&#062;<BR>ps(2) now equals the request.form without the dashes. Use it as you would have used the request.form. If this is still unclear, post your email address & I&#039ll send a quick, one-page sample<BR>leo<BR>


  5. #5
    mezaache@yahoo.com Guest

    Default RE: ASP DB

    &#060;%@ Language=VBScript &#037;&#062;<BR>&#060;%<BR>dim ps(6)<BR>ps(0)=request.form("SS")<BR>ps(0)=Trim(ps (0))<BR>ps(1)=len(ps(0))<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>for a=1 to ps(1)<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>ps(4)=ps(4)+1<BR>ps(3)=""<BR>ps(3)=InStr(1 ,ps(0),"-")<BR>ps(2)=ps(2) & Mid(ps(0),1,(ps(3)-1))<BR>ps(0)=Mid(ps(0),(ps(3)+1))<BR>else<BR>if len(ps(2))&#060;>(ps(1)-ps(4)) then<BR>ps(2)=ps(2) & ps(0)<BR>end if<BR>Exit For<BR>end if<BR>next<BR>set a=nothing<BR>else<BR>ps(2)=request.form("SS")<BR>e nd if &#037;&#062;<BR><BR> <BR>&#060;%<BR><BR>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open "DSN=Ameur"<BR>SSN=trim(Request.QueryString("SS")) <BR><BR>SQLtemp="select EESSN, FULLNAME, DOH FROM MyTable_OLD where EESSN=&#039" <BR>SQLtemp=SQLtemp & SSN & "&#039" <BR>set rstemp=conntemp.execute(SQLtemp)<BR> <BR>set rstemp=conntemp.execute(SQLtemp)<BR>set rstemp=conntemp.execute(SQLtemp)<BR>howmanyfields= rstemp.fields.count -1<BR><BR>&#037;&#062;<BR> &#060;table border=1>&#060;tr><BR> &#060;% &#039Put Headings On The Table of Field Names<BR> for i=0 to howmanyfields &#037;&#062;<BR> &#060;td>&#060;b>&#060;%=rstemp(i).name&#037;&#062 ;&#060;/B>&#060;/TD><BR> &#060;% next &#037;&#062;<BR> &#060;/tr><BR> &#060;% if rstemp.eof then &#037;&#062;<BR> "no record found please &#060;B>&#060;a href="AddAE.htm">go back and enter another number&#060;/a><BR><BR> <BR> &#060;%end if&#037;&#062;<BR> &#060;% &#039 Now lets grab all the records<BR> do while not rstemp.eof &#037;&#062;<BR> &#060;tr><BR> &#060;% for i = 0 to howmanyfields<BR> thisvalue=rstemp(i)<BR> If isnull(thisvalue) then<BR> thisvalue=""<BR> end if&#037;&#062;<BR> &#060;td valign=top>&#060;%=thisvalue&#037;&#062;&#060;/td><BR> &#060;% next &#037;&#062;<BR> &#060;/tr><BR> &#060;%rstemp.movenext<BR> loop&#037;&#062;<BR> &#060;/table><BR> &#060;%<BR> rstemp.close<BR> set rstemp=nothing<BR> conntemp.close<BR> set conntemp=nothing<BR>&#037;&#062;<BR><BR><BR>This is My code, still not working<BR>thanks for your help.

  6. #6
    Join Date
    Dec 1969
    Posts
    1,019

    Default RE: ASP DB

    Two things:<BR>1. In the code I supplied, change the request.form("SS") to request.querystring("SS"). This is how you passed the SSN.<BR>2. The code I supplied strips any dashes from the request.querysting("SS") and produces ps(2) as a dashless copy. You need to use ps(2), not the querystring when querying the database:<BR><BR>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open "DSN=Ameur"<BR>SSN=ps(2)<BR>&#039The above line sets SSN to the dashless ssn created by my code<BR><BR>SQLtemp="select EESSN, FULLNAME, DOH FROM MyTable_OLD where EESSN=&#039" <BR>SQLtemp=SQLtemp & SSN & "&#039" <BR>set rstemp=conntemp.execute(SQLtemp)<BR> <BR> Of course, you don&#039t have to use an array named ps, you could use different objects.<BR>

  7. #7
    Hi Leo Guest

    Default RE: ASP DB

    &#060;%<BR>dim ps(6)<BR>ps(0)=Request.QueryString("SS")<BR>ps(0)= Trim(ps(0))<BR>ps(1)=len(ps(0))<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>for a=1 to ps(1)<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>ps(4)=ps(4)+1<BR>ps(3)=""<BR>ps(3)=InStr(1 ,ps(0),"-")<BR>ps(2)=ps(2) & Mid(ps(0),1,(ps(3)-1))<BR>ps(0)=Mid(ps(0),(ps(3)+1))<BR>else<BR>if len(ps(2))&#060;>(ps(1)-ps(4)) then<BR>ps(2)=ps(2) & ps(0)<BR>end if<BR>Exit For<BR>end if<BR>next<BR>set a = nothing<BR>else<BR>ps(2) = Request.QueryString("SS")<BR>end if<BR>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open "DSN=Ameur"<BR>SSN=ps(2)<BR>ps(2)=trim(Request.Que ryString("SS"))<BR><BR>SQLtemp="select EESSN, FULLNAME, DOH FROM AE where EESSN=&#039" <BR>SQLtemp=SQLtemp & SSN & "&#039" <BR>set rstemp=conntemp.execute(SQLtemp)<BR> howmanyfields=rstemp.fields.count -1<BR>I did this but still notworking.<BR>Thanks a lot<BR>

  8. #8
    Join Date
    Dec 1969
    Posts
    1,019

    Default RE: ASP DB

    What is not working? Add this before you execute your SQL<BR>response.write SQLtemp<BR>You&#039ll be able to see if the dashes are removed or not.<BR><BR>Also, you added:<BR>ps(2)=trim(Request.QueryString("SS"))<BR >This isn&#039t necessary and doesn&#039t do anything since you don&#039t reference ps(2) anywhere else in the script.<BR><BR>

  9. #9
    To Leo Guest

    Default RE: ASP DB

    select EESSN, FULLNAME, DOH FROM AE where EESSN=&#039 117801429&#039 EESSN FULLNAME DOH <BR>"no record found please go back and enter another number<BR><BR> this is a test but I still got the same error.<BR>I did what you told me.<BR>sorry to bathere you again.

  10. #10
    To Leo Guest

    Default RE: ASP DB

    select EESSN, FULLNAME, DOH FROM AE where EESSN=&#039 117801429&#039 EESSN FULLNAME DOH <BR>"no record found please go back and enter another number<BR><BR> this is a test but I still got the same error.<BR>I did what you told me.<BR>sorry to bathere you again.<BR><BR>&#060;%<BR>dim ps(6)<BR>ps(0)=Request.QueryString("SS")<BR>ps(0)= Trim(ps(0))<BR>ps(1)=len(ps(0))<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>for a=1 to ps(1)<BR>if InStr(1,ps(0),"-")&#060;>0 then<BR>ps(4)=ps(4)+1<BR>ps(3)=""<BR>ps(3)=InStr(1 ,ps(0),"-")<BR>ps(2)=ps(2) & Mid(ps(0),1,(ps(3)-1))<BR>ps(0)=Mid(ps(0),(ps(3)+1))<BR>else<BR>if len(ps(2))&#060;>(ps(1)-ps(4)) then<BR>ps(2)=ps(2) & ps(0)<BR>end if<BR>Exit For<BR>end if<BR>next<BR>set a = nothing<BR>else<BR>ps(2) = trim( Request.QueryString("SS"))<BR>end if<BR>set conntemp=server.createobject("adodb.connection")<B R>conntemp.open "DSN=Ameur"<BR>SSN=ps(2)<BR>SSN=trim(Request.Query String("SS"))<BR>ps(2)=trim(Request.QueryString("S S"))<BR><BR>SQLtemp="select EESSN, FULLNAME, DOH FROM AE where EESSN=&#039" <BR>SQLtemp=SQLtemp & SSN & "&#039" <BR>Response.Write SQLtemp<BR>set rstemp=conntemp.execute(SQLtemp)<BR> howmanyfields=rstemp.fields.count -1<BR><BR>&#037;&#062;<BR> &#060;table border=1>&#060;tr><BR> &#060;% &#039Put Headings On The Table of Field Names<BR> for i=0 to howmanyfields &#037;&#062;<BR> &#060;td>&#060;b>&#060;%=rstemp(i).name&#037;&#062 ;&#060;/B>&#060;/TD><BR> &#060;% next &#037;&#062;<BR> &#060;/tr><BR> &#060;% if rstemp.eof then &#037;&#062;<BR> "no record found please &#060;B>&#060;a href="AddAE.htm">go back and enter another number&#060;/a><BR><BR> <BR> &#060;%end if&#037;&#062;

Posting Permissions

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