• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 985
  • Last Modified:

Number: -2147217908 Description: Command text was not set for the command object.

Hello all,

     I am having problems with this ASP that is supposed to write to a SQL table.  Here is my code, hopefully someone can help me out today.

CODE:

<% Option Explicit %>

<% On Error Resume Next %>

<% Dim strCash1, strChecks1, strCredits1, strTotals1 %>
<% Dim ConDB, rsNumbers, strSQL, strAdd %>

<% strCash1= Request.Form("txtcash[1]") %>
<% strChecks1 = Request.Form("txtchecks[1]") %>
<% strCredits1 = Request.Form("txtcredits[1]") %>
<% strTotals1 = Request.Form("txttotals[1]") %>


<% strSQL = "INSERT INTO GreenSheet1(Cash,Checks,Credits,Totals) " & _
   "VALUES('" & strCash1 & "','" & strCheck1 & "','" & strCredits1 & "','" & strTotals1 & "');" %>  


<% Set conDB = Server.CreateObject("ADODB.Connection") %>
<% conDB.Open "Provider=sqloledb;" & _
           "Data Source=database-server;" & _
           "Initial Catalog=CorpWeb;" & _
           "User Id=empnum;" & _
           "Password=monktard" %>

<%
      Set strAdd = ConDB.Execute(strSQL)

      If Err.Number <> 0 Then
          Response.Write "<body>"
          Response.Write "<p><b>The following Error has occured:</b></p>"
          Response.Write "Number: " & Err.Number & "<br>"
          Response.Write "Description: " & Err.Description & "<br>"
          Response.Write "Source: " & Err.Source & "<br>"

          Err.Clear
      Else
%>

<html>

<head>
<title></title>

</head>

<body>

<H3><font face="Tahoma">Green Sheet Numbers Added</font></H3>

</html>

<% End If %>
0
Ahelbling
Asked:
Ahelbling
  • 5
  • 4
1 Solution
 
Steve BinkCommented:
>>> Set strAdd = ConDB.Execute(strSQL)

You're executing SQL that does not return anything.  Use this syntax:

ConDB.Execute strSQL, strAdd

After execution, strAdd will hold the number of records affected.
0
 
fritz_the_blankCommented:
Okay, what happens if you do this?

<% strSQL = "INSERT INTO GreenSheet1(Cash,Checks,Credits,Totals) " & _
   "VALUES('" & strCash1 & "','" & strCheck1 & "','" & strCredits1 & "','" & strTotals1 & "');" %>  

response.write strSQL
response.end

I suspect that you have no values, and that these:

<% strCash1= Request.Form("txtcash[1]") %>
<% strChecks1 = Request.Form("txtchecks[1]") %>
<% strCredits1 = Request.Form("txtcredits[1]") %>
<% strTotals1 = Request.Form("txttotals[1]") %>

are not giving you values.

FtB
0
 
AhelblingAuthor Commented:
Here is the code for the page that is supposed to pass the values:

<html>
<head>
    <title>A test</title>
    <script type="text/javascript">
    function calculate(rowIndex){
        var formObject = document.GreenSheet;    // Creating reference to form
        var cash = formObject.elements['cash['+rowIndex+']'].value+"";
        var checks = formObject.elements['checks['+rowIndex+']'].value+"";
        var credits = formObject.elements['credits['+rowIndex+']'].value+"";
       
        if(!isNaN(cash) && !isNaN(checks) && !isNaN(credits)){ // All values are numeric
            formObject.elements['total['+rowIndex+']'].value = cash/1 + checks/1 + credits/1;
           
        }
               
    }
    </script>
</head>
<body>
<FORM name="GreenSheet" METHOD="POST" ACTION="NumberGenGreenSheet.asp">

<table>
    <tr>
        <td height="23"></td>
        <td><div align="center">Cash</div></td>
        <td><div align="center">Checks</div></td>
        <td><div align="center">Credits</div></td>
            <td><div align="center">Total</div></td>
    </tr>

<tr><td><div align="right">Per System Reports</div></td><td><input type="text" name="cash[1]" onchange="calculate(1)"></td><td><input type="text" name="checks[1]" onchange="calculate(1)"></td><td><input type="text" name="credits[1]" onchange="calculate(1)"></td><td><input type="text" name="total[1]" readonly>
<tr><td><div align="right">Overring</div></td><td><input type="text" name="cash[2]" onchange="calculate(2)"></td><td><input type="text" name="checks[2]" onchange="calculate(2)"></td><td><input type="text" name="credits[2]" onchange="calculate(2)"></td><td><input type="text" name="total[2]" readonly>
<tr><td><div align="right">Store Expense</div></td><td><input type="text" name="cash[3]" onchange="calculate(3)"></td><td><input type="text" name="checks[3]" onchange="calculate(3)"></td><td><input type="text" name="credits[3]" onchange="calculate(3)"></td><td><input type="text" name="total[3]" readonly>
<tr><td><div align="right">Refunds</div></td><td><input type="text" name="cash[4]" onchange="calculate(4)"></td><td><input type="text" name="checks[4]" onchange="calculate(4)"></td><td><input type="text" name="credits[4]" onchange="calculate(4)"></td><td><input type="text" name="total[4]" readonly>
<tr><td><div align="right">Reclassifications</div></td><td><input type="text" name="cash[5]" onchange="calculate(5)"></td><td><input type="text" name="checks[5]" onchange="calculate(5)"></td><td><input type="text" name="credits[5]" onchange="calculate(5)"></td><td><input type="text" name="total[5]" readonly>
<tr><td colspan="5"><div align="center">
  <input name="Submit" type="Submit" value="Submit">
</div></td>
</table>

</form>

</body>

</html>

Thanks,
Andrew
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
fritz_the_blankCommented:
Okay, let's start with this-I am worried about your field names. Place this at the top of your processing page and let me know what you get:

for each objField in Request.form
  response.write(objField & ": " & request.form(objField) & "<BR>")
next

response.end

This will show the field names and the passed values.

FtB
0
 
AhelblingAuthor Commented:
Here is what i get:


cash[1]: 1
total[2]:
checks[1]: 2
cash[5]:
total[5]:
credits[1]: 3
cash[2]:
credits[2]:
credits[3]:
checks[4]:
credits[4]:
credits[5]:
total[1]: 6
checks[5]:
checks[2]:
cash[3]:
checks[3]:
total[3]:
Submit: Submit
cash[4]:
total[4]:
0
 
fritz_the_blankCommented:
Okay, I found the error. Your field names are:

cash[1]: 1
checks[1]: 2
credits[1]: 3

but you are looking for txtcash[1] and so forth here:

<% strCash1= Request.Form("txtcash[1]") %>
<% strChecks1 = Request.Form("txtchecks[1]") %>
<% strCredits1 = Request.Form("txtcredits[1]") %>
<% strTotals1 = Request.Form("txttotals[1]") %>
0
 
fritz_the_blankCommented:
So, change these lines:

<% strCash1= Request.Form("cash[1]") %>
<% strChecks1 = Request.Form("checks[1]") %>
<% strCredits1 = Request.Form("credits[1]") %>
<% strTotals1 = Request.Form("total[1]") %>

Note alos the difference between total and totals!

FtB
0
 
AhelblingAuthor Commented:
Right on - thanks a lot - i am pretty rusty with a lot of this. I am SUPPOSED to be doing most of the web programming, and have done all of it here, but with all the cutbacks i have had to be a one horse cart around here. Sure wish i had more time to practice.

Thanks and good job!
Andrew
0
 
fritz_the_blankCommented:
Glad to have helped.

As an aside, I think that routinet had a good point in http:#13939608

Instead of this:

 Set strAdd = ConDB.Execute(strSQL)


all you really need is this:

 ConDB.Execute(strSQL)

FtB
0
 
AhelblingAuthor Commented:
I did, thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now