Experts: I am still attempting to add more than 255 characters to a memo field in Foxpro 6.0.
I am now getting the message above. Here is the entire inssert and update query code.
sub AddRecord
set insconn=server.CreateObject("ADODB.Connection")
set insrs=server.CreateObject("ADODB.Recordset")
insconn.Open "DSN=ifis"
InsQry="Insert into change_requestrev1 (track_no, subject, req_date, initiator, eff_date, req_desc, bus_value, progrun, progname, t_details, back_plan, risks, app_date, app_by, recommend, comp_date) values ("
InsQry=InsQry & "" & formatnumber(int(trim(Request.Form("strRecNo"))),0,0,0,0) & ",'"
InsQry=insQry & Replace(trim(Request.Form("subject")), "'", "''") &"',"
InsQry=InsQry & "{^" & cstr(year(cdate(Request.Form("req_date")))) & "-" & cstr(month(cdate(Request.Form("req_date")))) & "-" & cstr(day(cdate(Request.Form "req_date")))) "},'"
InsQry=insQry & Replace(trim(Request.Form("initiator")), "'", "''") & "',"
InsQry=InsQry & "{^" & cstr(year(cdate(Request.Form("eff_date")))) & "-" & cstr(month(cdate(Request.Form("eff_date")))) & "-" & cstr(day(cdate(Request.Form("eff_date")))) "},'"
if Request.form("eff_date")="" then
InsQry=InsQry & "CTOD('//'),'"
end if
**THIS WILL BREAK UP THE LONG STRING IF MORE THAN 200 CHARACTERS ARE ENTERED**
if len(Request.form("req_desc"))>200 then
Workstring=mid(Request.form("req_desc"), 201, len(Request.form("req_desc")))
req_desc=Replace(Mid(Request.Form("req_desc"), 1, 200), "'", "''")
InsQry=insQry & Replace(Mid(Request.Form("req_desc"), 1, 200), "'", "''") & "','"
else
req_desc=Replace(Request.Form("req_desc"), "'", "''")
InsQry=insQry & Replace(trim(Request.Form("req_desc")), "'", "''") & "','"
end if
InsQry=insQry & Replace(trim(Request.Form("bus_value")), "'", "''") & "',"
if Request.Form ("progrun")="True" then
InsQry=InsQry & ".T.,'"
end if
if Request.Form ("progrun")="False" then
InsQry=InsQry & ".F.,'"
end if
if Request.Form ("progrun")="" then
InsQry=InsQry & ".F.,'"
end if
InsQry=insQry & Replace(trim(Request.Form("progname")), "'", "''") & "','"
InsQry=insQry & Replace(trim(Request.Form("t_details")), "'", "''") & "','"
InsQry=insQry & Replace(trim(Request.Form("back_plan")), "'", "''") & "','"
InsQry=insQry & Replace(trim(Request.Form("risks")), "'", "''") & "',"
InsQry=InsQry & "{^" & cstr(year(cdate(Request.Form("app_date")))) & "-" & cstr(month(cdate(Request.Form("app_date")))) & "-" & cstr(day(cdate(Request.Form("app_date")))) &"},'"
if Request.form("app_date")="" then
InsQry=InsQry & "CTOD('//'),'"
end if
InsQry=insQry & Replace(trim(Request.Form("app_by")), "'", "''") & "','"
InsQry=insQry & Replace(trim(Request.Form("recommend")), "'", "''") &"',"
InsQry=InsQry & "{^" & cstr(year(cdate(Request.Form("comp_date")))) & "-" & cstr(month(cdate(Request.Form("comp_date")))) & "-" & cstr(day(cdate(Request.Form("comp_date")))) &"})"
if Request.form("comp_date")="" then
InsQry=InsQry & "CTOD('//'))"
end if
Response.Write "<br>"
Insrs.open insconn.Execute(InsQry)
Response.Write insQry
Response.Write "<br>"
Response.Write "This is req_desc " & req_desc & "<br>"
Response.Write "The WorkString is " & WorkString
*** END OF INSERT ***
***UPDATE IF REQ_DESC IS LONGER THAN 200 CHARS ***
if WorkString<>"" then
set connA=server.CreateObject("ADODB.Connection")
set rsA=server.CreateObject("ADODB.Recordset")
connA.Open "DSN=ifis"
if err then
response.Write err.Source
Response.Write err.Number
Response.Write err.Description
End if
sql4="Update change_requestrev1 set req_desc=" & "'" & req_desc + Workstring & "'"
sql4=sql4 & " where change_requestrev1.track_no=" & strTrackNo & ""
I have tried both these methods but still get the same error
'rsA.Open connA.Execute(sql4)
rsA.Open connA.Execute(sql4),,adOpenDynamic, adLockOptimistic
Response.Write sql4
end if
end sub
Any help would be greatly appreciated.
by: bigbillydotcomPosted on 2005-09-01 at 11:48:29ID: 14804880
*****SIMPLE ANSWER BELOW - BUT PLEASE READ SO YOU UNDERSTAND WHY***** nDynamic, adLockOptimistic
********** ********** ***** ********** ********** ***** t("ADODB.C onnection" ) )+" ' ," +" ' )"
********** ********** ***** ********** ********** ***** t("ADODB.C onnection" ) DODB.Recor dset") r>"
All of these constructs are wrong
Insrs.open insconn.Execute(InsQry)
'rsA.Open connA.Execute(sql4)
rsA.Open connA.Execute(sql4),,adOpe
I think you are confusing the .Open method of the connection obejct and the .Open method of the recordset object
Also - you are trying to open a recordset - and the recordset you are trying to open, you are passing an execution of a connection object which, like the error message says:
ADODB.Recordset 3001 Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another
The only time you need to use a recordset object is to hold data that will be returned from the execution of a valid SQL command (which requires a connection object - and a connection object requires a connection string)
Since this code is in a Sub (as opposed to a function) I THINK all you are trying to do here is run a sql INSERT statement followed by a sql UPDATE statement - AND you are not actually "populating" a recordset, like you would if you were getting data, for instance, to display in a grid
ALSO - I don't see any object cleanup in you code above - THIS IS ABSOLUTELY CRITICAL
SINCE ASP PROGRAMMING IS BASICALLY "STATELESS" - THER EIS NO AUTOMATIC OBJECTION TRASH COLLECTION - LEAVING THESE OBJECTS HANGING AROUND WILL CAUSE SEVERE PROBLEMS
********SO***********
here is the bigbillydotcom breakdown of how this all works ( I am using your examples from above, so I am just assuming your connection string is working):
**************************
Scenario 1 - Executing a SQL statement that doesnt return a recordset
**************************
'create a connection object
set insconn=server.CreateObjec
'open the connection using a valid connection string
insconn.Open "DSN=ifis"
'create a valid sql statement - this sql statement once created should be able to be run in a query window without error
'I am going to keep it simple for now
'this statement will be created using input from an asp form
mysql = "INSERT INTO [Customers] (FirstName,LastName) VALUES ("
'now add form data - remember to wrap string values in single quote marks
mysql = mysql +" ' "+request.form("FirstName"
mysql = mysql +" ' "+request.form("LastName")
'the result of the lines above need to be a valid sql statement like the next line
'INSERT INTO [Customers] (FirstName,LastName) VALUES ('Billy','Saxon')
'then - since we are not RETURNING any data by running that sql statement, we need only execute it
'using the connection object we just opened
insconn.Execute(mysql)
'now we need to close the connection object
insconn.Close
'now we need to destroy the object and release the memory for other processes
set insconn = Nothing
So - Scenario 1 works for any sql statement that DOESNT return any data
**************************
Scenario 2 - Executing a SQL statement that DOES return DATA, and using that data in a recordset
**************************
'create a connection object
set insconn=server.CreateObjec
'open the connection using a valid connection string
insconn.Open "DSN=ifis"
'create a valid sql statement - this sql statement once created should be able to be run in a query window without error
'I am going to keep it simple for now
'this statement will be add data into a recordset and show data in the browser
mysql = "Select * Customers"
'then - since we ARE RETURNING data, we need to create an object to hold that data
'then use the connection object to go and fetch the data and put it in that object
set rsA=server.CreateObject("A
'using the connection object we opened above - we execute the sql statement and assign the value of that execution
'to the recrodset object just created
set rsA = insconn.Execute(mysql)
'no we can do recordset stuff
If not (rsA.Bof or rsA.Eof) then
Do until rsA.eof
'show data
Response.Write "First Name:"+rsA("Firstname")+" Last Name:"+rsA("Lastname")+"<b
rsA.MoveNext
loop
End if
'now we need to close that recordset object
rsA.Close
'now we need to destroy that object
Set rsA = Nothing
'now we need to close the connection object
insconn.Close
'now we need to destroy the object and release the memory for other processes
set insconn = Nothing
I hope that helps you to understand the inner working of the connection and recordset objects
Good Luck