Andrew
asked on
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,Cr edits,Tota ls) " & _
"VALUES('" & strCash1 & "','" & strCheck1 & "','" & strCredits1 & "','" & strTotals1 & "');" %>
<% Set conDB = Server.CreateObject("ADODB .Connectio n") %>
<% 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 %>
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,Cr
"VALUES('" & strCash1 & "','" & strCheck1 & "','" & strCredits1 & "','" & strTotals1 & "');" %>
<% Set conDB = Server.CreateObject("ADODB
<% 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 %>
Okay, what happens if you do this?
<% strSQL = "INSERT INTO GreenSheet1(Cash,Checks,Cr edits,Tota ls) " & _
"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
<% strSQL = "INSERT INTO GreenSheet1(Cash,Checks,Cr
"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
ASKER
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 +']'].valu e+"";
var checks = formObject.elements['check s['+rowInd ex+']'].va lue+"";
var credits = formObject.elements['credi ts['+rowIn dex+']'].v alue+"";
if(!isNaN(cash) && !isNaN(checks) && !isNaN(credits)){ // All values are numeric
formObject.elements['total ['+rowInde x+']'].val ue = cash/1 + checks/1 + credits/1;
}
}
</script>
</head>
<body>
<FORM name="GreenSheet" METHOD="POST" ACTION="NumberGenGreenShee t.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</di v></td>
<td><div align="center">Total</div> </td>
</tr>
<tr><td><div align="right">Per System Reports</div></td><td><inp ut type="text" name="cash[1]" onchange="calculate(1)"></ td><td><in put type="text" name="checks[1]" onchange="calculate(1)"></ td><td><in put type="text" name="credits[1]" onchange="calculate(1)"></ td><td><in put type="text" name="total[1]" readonly>
<tr><td><div align="right">Overring</di v></td><td ><input type="text" name="cash[2]" onchange="calculate(2)"></ td><td><in put type="text" name="checks[2]" onchange="calculate(2)"></ td><td><in put type="text" name="credits[2]" onchange="calculate(2)"></ td><td><in put type="text" name="total[2]" readonly>
<tr><td><div align="right">Store Expense</div></td><td><inp ut type="text" name="cash[3]" onchange="calculate(3)"></ td><td><in put type="text" name="checks[3]" onchange="calculate(3)"></ td><td><in put type="text" name="credits[3]" onchange="calculate(3)"></ td><td><in put 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><in put type="text" name="checks[4]" onchange="calculate(4)"></ td><td><in put type="text" name="credits[4]" onchange="calculate(4)"></ td><td><in put type="text" name="total[4]" readonly>
<tr><td><div align="right">Reclassifica tions</div ></td><td> <input type="text" name="cash[5]" onchange="calculate(5)"></ td><td><in put type="text" name="checks[5]" onchange="calculate(5)"></ td><td><in put type="text" name="credits[5]" onchange="calculate(5)"></ td><td><in put 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
<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[
var checks = formObject.elements['check
var credits = formObject.elements['credi
if(!isNaN(cash) && !isNaN(checks) && !isNaN(credits)){ // All values are numeric
formObject.elements['total
}
}
</script>
</head>
<body>
<FORM name="GreenSheet" METHOD="POST" ACTION="NumberGenGreenShee
<table>
<tr>
<td height="23"></td>
<td><div align="center">Cash</div><
<td><div align="center">Checks</div
<td><div align="center">Credits</di
<td><div align="center">Total</div>
</tr>
<tr><td><div align="right">Per System Reports</div></td><td><inp
<tr><td><div align="right">Overring</di
<tr><td><div align="right">Store Expense</div></td><td><inp
<tr><td><div align="right">Refunds</div
<tr><td><div align="right">Reclassifica
<tr><td colspan="5"><div align="center">
<input name="Submit" type="Submit" value="Submit">
</div></td>
</table>
</form>
</body>
</html>
Thanks,
Andrew
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
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
ASKER
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]:
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]:
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] ") %>
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]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Thanks and good job!
Andrew
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
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
ASKER
I did, thanks!
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.