OnChange & RecordCount

Results 1 to 3 of 3

Thread: OnChange & RecordCount

  1. #1
    Join Date
    Dec 1969

    Default OnChange & RecordCount

    I have a page which contains a pull down menu the menu contains numbers 1 to 10.<BR>OnChange and on selection of for example &#039;7&#039; the person should get the values of the 7th row from a table if its &#039;8&#039; then he gets value of 8th row. which he can display as example :<BR><BR>The employee name is &#060;%=RS("empname")%&#062;<BR><BR>If the user selects 7 from the menu , he should get the name written in the 7th row and so on.<BR>All well till now. I get the value of the pull down number selected and i store it in <BR>&#060;%<BR>rowNumber = request("selectedMenu")<BR>%&#062;<BR>Now what should be the SQL query ? maybe I am taking the wrong approach and some wrong syntax too I guess.<BR>Please advice<BR>the below being a piece of my code.<BR>&#060;%<BR><BR>set con= Server.CreateObject("ADODB.Connection")<BR>con.Ope n "FILEDSN=rnd.dsn"<BR>set RS2 = con.Execute("select * from table where Empname=" & "&#039;" & Request("Empname") & "&#039;")<BR>rCount= RS2.recordcount<BR>set RS = con.Execute("select * from table where Empname=" & "&#039;" & Request("Empname") & "&#039;" & "AND" & "&#039;" rCount= & rowNumber)<BR> <BR>while not RS.EOF<BR><BR>.<BR>.<BR>.<BR>%&#062;<BR><BR>The employee name is &#060;%=RS("empname")%&#062;<BR><BR>.<BR>.<BR><BR> Thank you in advance for helping me<BR>Beginner

  2. #2
    Join Date
    Dec 1969

    Default Maybe you should show more code

    It&#039;s hard to tell, from what you describe, what code is on the page with the &#060;SELECT&#062; and what code is on the next page.<BR><BR>But, anyway...<BR><BR>&#060;SELECT Name="Empname" onChange="this.form.submit();"&#062;<BR>&#060;OPTI ON&#062;-- please select a name --<BR>&#060;OPTION&#062;John Doe<BR>&#060;OPTION&#062;Mary Roe<BR>...<BR>&#060;/SELECT&#062;<BR><BR>If you do that and then do your<BR><BR>set RS2 = con.Execute("select * from table where Empname=&#039;" & Request("Empname") & "&#039;")<BR><BR>You should, indeed, get ONE RECORD with that particular employee. Assuming, of course, you don&#039;t have two employess with the same name. (Which is why you really should be using something like EmployeeID instead of Empname, but that&#039;s another discussion.)<BR><BR>NOW...<BR><BR>What mystifies me is this code:<BR><BR>&nbsp; &nbsp; rCount= RS2.recordcount<BR><BR>Ummm... You just selected one and only one employee from the table. What&#039;s the point of that statement??? Not that it would work, anyway. You will *always* get -1 for rCount from that. See the ASPFAQs, category "Databases, Errors" to see why.<BR><BR>&nbsp &nbsp; set RS = con.Execute("select * from table where " _<BR>&nbsp &nbsp; &nbsp &nbsp; & "Empname=" & "&#039;" & Request("Empname") & "&#039;" _<BR>&nbsp &nbsp; &nbsp &nbsp; & " AND rCount=" & rowNumber)<BR><BR>I fixed your SQL Syntax in that, but it still makes no sense.<BR><BR>Why would you destroy the Recordset you just created, that got the person who was selected on the prior page? And it doesn&#039;t make lots of sense from a field names perspective either. You just got a VBS variable name rCount. Now you decide that rCount is the field name but rowNumber is the VBS variable??? Huh? <BR><BR>&nbsp; &nbsp; while not RS.EOF<BR><BR>??? Huh? You *should* have only one record. So why do you need a WHILE loop for only one record.<BR><BR>&nbsp; &nbsp; The employee name is &#060;%=RS("empname")%&#062;<BR><BR>Ummm...if the only purpose of this was to get the name of the employee... Didn&#039;t you already get that from the first page, via<BR>&nbsp; &nbsp; Request("Empname")<BR>??? If you don&#039;t want anything else from the DB, why are you bothering with the DB on this second page???<BR><BR>***************<BR><BR>In short, maybe you need to try to step back a few steps and try describing the problem again. In small pieces. <BR><BR><BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default My be this can solve ur problem

    if i am not wrong i have understude ur problem<BR>You want to display the dorpdown menu with all the values a well as u want to display the selected value also....<BR><BR>according to me u can do this inside ur page<BR><BR>&#060;% <BR> dim RowNumber<BR> dim intCounter<BR> dim strName<BR><BR> RowNumber=Request("selectedMenu")<BR> set con= Server.CreateObject("ADODB.Connection")<BR> con.Open "FILEDSN=rnd.dsn"<BR> set RS = con.Execute("select * from table")<BR> <BR> intCounter=0<BR> while not RS.EOF<BR> &#039;write ur code to fill the drop down menu.<BR> if intCounter=RowNumber then<BR> strName=RS("empname")<BR> end if<BR> intCounter=intCounter+1<BR> loop<BR><BR> Response.write "The Employee Name is: " & strName<BR><BR>%&#062;<BR><BR>I hope the above mentioned code will solve ur Problem<BR>

Posting Permissions

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