How to handle, when SQL command returns a single value

Ask a Question related to ASP Components, Design and Development.

  1. #1

    Default How to handle, when SQL command returns a single value

    Hi,

    I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it returns a single value. The following code fails when "objRst.open strQ" is executed. Can somebody suggest me how to overcome this problem.

    Any Help is appreciated.
    Thanks in advance,
    Vasanth
    -----------------------
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbFilePath & ";"
    Set objRst = Server.CreateObject("ADODB.Recordset")
    strQ = "Select MAX(index) from library where index like '*B-*';"
    objRst.Open strQ
    cmd.execute
    while Not objRst.EOF
    index=objRst("index")
    objrst.movenext
    Wend
    Set objRst = nothing
    objConnect.Close
    Set objConnect = nothing
    %>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <form action="newupdate.asp" method=post>
    index:<%=index%>
    </form>
    </body>
    </html>
    ----------------------------------------
    I also tried the following alternative. Here it fails when I try to print "objRst" on the page.
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbFilePath & ";"
    Set cmd = Server.CreateObject("ADODB.Command")
    Set cmd.ActiveConnection = objConnect
    strQ = "Select MAX(index) from library where index like '*B-*';"
    cmd.commandtext=strQ
    set objRst = cmd.execute
    objConnect.Close
    Set objConnect = nothing
    %>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <form action="newupdate.asp" method=post>
    index:<%=objRst%>
    </form>
    </body>
    </html>
    vasanth kumar Guest

  2. Similar Questions and Discussions

    1. #40704 [NEW]: strip_tags does not handle single quotes correctly (another regression)
      From: email at steffenweber dot net Operating system: Linux PHP version: 5.2.1 PHP Bug Type: Strings related Bug...
    2. #40637 [NEW]: strip_tags does not handle single quotes correctly (regression)
      From: email at steffenweber dot net Operating system: Linux PHP version: 5.2.1 PHP Bug Type: Strings related Bug...
    3. msyql command line tool can't handle del character
      Mysql command line editing works perfectly with history, arrows keys, but print a ~ when I use the del char. It is a bug or a bad configuration?...
    4. what is the correct way to handle empty database returns?
      If I do something like : $result = mysql_query($query); $dbArray = dbResultIntoKeyArray($result); and this is the function: function...
    5. how to handle single quotation marks
      Just wonder how you guys handle the single quatation marks when you write the value of a text input into SQL server. Thanks! * * * Sent via...
  3. #2

    Default How to handle, when SQL command returns a single value

    Hi,

    I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it returns a single value. The following code fails when "objRst.open strQ" is executed. Can somebody suggest me how to overcome this problem.

    Any Help is appreciated.
    Thanks in advance,
    Vasanth
    -----------------------
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbFilePath & ";"
    Set objRst = Server.CreateObject("ADODB.Recordset")
    strQ = "Select MAX(index) from library where index like '*B-*';"
    objRst.Open strQ
    cmd.execute
    while Not objRst.EOF
    index=objRst("index")
    objrst.movenext
    Wend
    Set objRst = nothing
    objConnect.Close
    Set objConnect = nothing
    %>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <form action="newupdate.asp" method=post>
    index:<%=index%>
    </form>
    </body>
    </html>
    ----------------------------------------
    I also tried the following alternative. Here it fails when I try to print "objRst" on the page.
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbFilePath & ";"
    Set cmd = Server.CreateObject("ADODB.Command")
    Set cmd.ActiveConnection = objConnect
    strQ = "Select MAX(index) from library where index like '*B-*';"
    cmd.commandtext=strQ
    set objRst = cmd.execute
    objConnect.Close
    Set objConnect = nothing
    %>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <form action="newupdate.asp" method=post>
    index:<%=objRst%>
    </form>
    </body>
    </html>
    vasanth kumar Guest

  4. #3

    Default Re: How to handle, when SQL command returns a single value

    The problem is that you do not have a column named INDEX in your recordset.
    You have an unnamed column that represents MAX(index). You can either name
    it in your query or use the index value in the recordset to get it. (Not
    the same "index" as in your column name.)

    "Select MAX(index) as TheMax from library..."
    index = objRst.Fields.Item("TheMax").Value

    Or, leave your query as is and do:

    index = objRst.Fields.Item(0).Value

    Ray at work

    "vasanth kumar" <vasanth.kumar@eds.com> wrote in message
    news:%23J5ak5ZaEHA.1248@TK2MSFTNGP11.phx.gbl...
    Hi,

    I have a problem in dealing with the return value of the SQL command. I
    know how to do, when SQL command returns Recordsets. But in my case it
    returns a single value. The following code fails when "objRst.open strQ" is
    executed. Can somebody suggest me how to overcome this problem.

    Any Help is appreciated.
    Thanks in advance,
    Vasanth
    -----------------------
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    mdbFilePath & ";"
    Set objRst = Server.CreateObject("ADODB.Recordset")
    strQ = "Select MAX(index) from library where index like '*B-*';"
    objRst.Open strQ
    cmd.execute
    while Not objRst.EOF
    index=objRst("index")
    objrst.movenext
    Wend


    Ray at Guest

  5. #4

    Default Re: How to handle, when SQL command returns a single value

    The problem is that you do not have a column named INDEX in your recordset.
    You have an unnamed column that represents MAX(index). You can either name
    it in your query or use the index value in the recordset to get it. (Not
    the same "index" as in your column name.)

    "Select MAX(index) as TheMax from library..."
    index = objRst.Fields.Item("TheMax").Value

    Or, leave your query as is and do:

    index = objRst.Fields.Item(0).Value

    Ray at work

    "vasanth kumar" <vasanth.kumar@eds.com> wrote in message
    news:%23J5ak5ZaEHA.1248@TK2MSFTNGP11.phx.gbl...
    Hi,

    I have a problem in dealing with the return value of the SQL command. I
    know how to do, when SQL command returns Recordsets. But in my case it
    returns a single value. The following code fails when "objRst.open strQ" is
    executed. Can somebody suggest me how to overcome this problem.

    Any Help is appreciated.
    Thanks in advance,
    Vasanth
    -----------------------
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    mdbFilePath & ";"
    Set objRst = Server.CreateObject("ADODB.Recordset")
    strQ = "Select MAX(index) from library where index like '*B-*';"
    objRst.Open strQ
    cmd.execute
    while Not objRst.EOF
    index=objRst("index")
    objrst.movenext
    Wend


    Ray at Guest

  6. #5

    Default Re: How to handle, when SQL command returns a single value

    Thanks for the help. It worked.

    -Vasanth
    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:OH8pRLaaEHA.212@TK2MSFTNGP12.phx.gbl...
    > The problem is that you do not have a column named INDEX in your
    recordset.
    > You have an unnamed column that represents MAX(index). You can either
    name
    > it in your query or use the index value in the recordset to get it. (Not
    > the same "index" as in your column name.)
    >
    > "Select MAX(index) as TheMax from library..."
    > index = objRst.Fields.Item("TheMax").Value
    >
    > Or, leave your query as is and do:
    >
    > index = objRst.Fields.Item(0).Value
    >
    > Ray at work
    >
    > "vasanth kumar" <vasanth.kumar@eds.com> wrote in message
    > news:%23J5ak5ZaEHA.1248@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > I have a problem in dealing with the return value of the SQL command.
    I
    > know how to do, when SQL command returns Recordsets. But in my case it
    > returns a single value. The following code fails when "objRst.open strQ"
    is
    > executed. Can somebody suggest me how to overcome this problem.
    >
    > Any Help is appreciated.
    > Thanks in advance,
    > Vasanth
    > -----------------------
    > Set objConnect = Server.CreateObject("ADODB.Connection")
    > objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > mdbFilePath & ";"
    > Set objRst = Server.CreateObject("ADODB.Recordset")
    > strQ = "Select MAX(index) from library where index like '*B-*';"
    > objRst.Open strQ
    > cmd.execute
    > while Not objRst.EOF
    > index=objRst("index")
    > objrst.movenext
    > Wend
    >
    >

    vasanth kumar Guest

  7. #6

    Default Re: How to handle, when SQL command returns a single value

    Thanks for the help. It worked.

    -Vasanth
    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:OH8pRLaaEHA.212@TK2MSFTNGP12.phx.gbl...
    > The problem is that you do not have a column named INDEX in your
    recordset.
    > You have an unnamed column that represents MAX(index). You can either
    name
    > it in your query or use the index value in the recordset to get it. (Not
    > the same "index" as in your column name.)
    >
    > "Select MAX(index) as TheMax from library..."
    > index = objRst.Fields.Item("TheMax").Value
    >
    > Or, leave your query as is and do:
    >
    > index = objRst.Fields.Item(0).Value
    >
    > Ray at work
    >
    > "vasanth kumar" <vasanth.kumar@eds.com> wrote in message
    > news:%23J5ak5ZaEHA.1248@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > I have a problem in dealing with the return value of the SQL command.
    I
    > know how to do, when SQL command returns Recordsets. But in my case it
    > returns a single value. The following code fails when "objRst.open strQ"
    is
    > executed. Can somebody suggest me how to overcome this problem.
    >
    > Any Help is appreciated.
    > Thanks in advance,
    > Vasanth
    > -----------------------
    > Set objConnect = Server.CreateObject("ADODB.Connection")
    > objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > mdbFilePath & ";"
    > Set objRst = Server.CreateObject("ADODB.Recordset")
    > strQ = "Select MAX(index) from library where index like '*B-*';"
    > objRst.Open strQ
    > cmd.execute
    > while Not objRst.EOF
    > index=objRst("index")
    > objrst.movenext
    > Wend
    >
    >

    vasanth kumar Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139