Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Set rs = objConn.execute(Select_Statement)

Hi,

Does anyone know the awnser to the following ?

I want a user on my site to type his/her query into a text field and then display the output of the select query in a table on screen.

let's say that the user typed in the following query:

Select My_Field from My_Table WHERE My_Field > 10;
and that it is stored in a variable called Select_Statement

I'd do:

[code]
Set rs = objConn.execute(Select_Statement)
[/code]

I know I can now acces the result with the following code:

[code]
Set rs = objConn.execute(Select_Statement)
response.write("")
while not rs.EOF
response.write("")
loop
response.write("
" & rs.Fields("My_Field").value & " 
")
[/code]

But in this case I didn't now in designtime what the query would look like. I'd rather type something like this:

[code]
Set rs = objConn.execute(Select_Statement)
response.write("")
Field_nr = 1 'initialize
while rs.Fields(Fieldnr)
response.write("")
Field_nr = Field_nr + 1 'increment
loop

response.write("") ' Start a new row

while not rs.EOF
Field_nr = 1 'initialize
while rs.Fields(Fieldnr)
response.write("")
Field_nr = Field_nr + 1 'increment
loop
rs.movenext
response.write("") ' Start a new row
Loop
response.write("
" & rs.Fields(Field_nr).name & " 
" & rs.Fields(Field_nr).value & " 
")
[/code]

Does Anyone know how I should write this in proper ASP...


;-)
-mac-
mailto:programmersheaven@mac-doggie.nl
the Netherlands...

Comments

  • Anjuna MoonAnjuna Moon Posts: 89Member
    Hi,
    this is a way of doing it (just showing you the relevant code):

    set rs=conn.execute(query)
    do while not rs.eof
    for t=0 to rs.Fields.count-1
    nextFieldValue=rs(t)

    ' Then do what it is you do with the field value...

    next
    loop
    rs.close





    : Hi,
    :
    : Does anyone know the awnser to the following ?
    :
    : I want a user on my site to type his/her query into a text field and then display the output of the select query in a table on screen.
    :
    : let's say that the user typed in the following query:
    :
    : Select My_Field from My_Table WHERE My_Field > 10;
    : and that it is stored in a variable called Select_Statement
    :
    : I'd do:
    :
    : [code]
    : Set rs = objConn.execute(Select_Statement)
    : [/code]
    :
    : I know I can now acces the result with the following code:
    :
    : [code]
    : Set rs = objConn.execute(Select_Statement)
    : response.write("")
    : while not rs.EOF
    : response.write("")
    : loop
    : response.write("
    " & rs.Fields("My_Field").value & " 
    ")
    : [/code]
    :
    : But in this case I didn't now in designtime what the query would look like. I'd rather type something like this:
    :
    : [code]
    : Set rs = objConn.execute(Select_Statement)
    : response.write("")
    : Field_nr = 1 'initialize
    : while rs.Fields(Fieldnr)
    : response.write("")
    : Field_nr = Field_nr + 1 'increment
    : loop
    :
    : response.write("") ' Start a new row
    :
    : while not rs.EOF
    : Field_nr = 1 'initialize
    : while rs.Fields(Fieldnr)
    : response.write("")
    : Field_nr = Field_nr + 1 'increment
    : loop
    : rs.movenext
    : response.write("") ' Start a new row
    : Loop
    : response.write("
    " & rs.Fields(Field_nr).name & " 
    " & rs.Fields(Field_nr).value & " 
    ")
    : [/code]
    :
    : Does Anyone know how I should write this in proper ASP...
    :
    :
    : ;-)
    : -mac-
    : mailto:programmersheaven@mac-doggie.nl
    : the Netherlands...
    :
    :

  • roy_techroy_tech Posts: 2Member
    Let the user type the sql in the text box and you can get that sql into a variable. Let us say that variable is select_sql.

    When you create the recordset...

    Set rs = objconn.execute(select_sql)
    Dim ArrRS
    ArrRS= rs.getrows() ' This will get you all the selected rows into the ArrRS array.

    ArrRS is a two dimensional array.

    UBound(ArrRS,1) has all the columns and UBound(arrRS,2) has all the rows from the select query.

    Now you can use the loop(Do While) to generate the HTML.
Sign In or Register to comment.