|
 |
asp_databases thread: Command text was not set for the command object.
Message #1 by "Lan Chi Tran" <lanchi1975@y...> on Thu, 26 Jul 2001 20:15:18
|
|
Hi Expert,
I went back and changed all the =3D and =20 as you said and those errors
really go away. Thanks for that. However, another error came up.
Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'
Command text was not set for the command object.
/ASP_Modify/response_create_entries7.asp,
*************************************************
LINE (set rstemp=objConn.execute(SQLstr))
******************************************
<%
dim objConn, rs, names, values, SQL, SQLstr, rstemp
Set objConn = Server.CreateObject ("ADODB.Connection")
objConn.Open "testdata"
set rstemp=objConn.execute(SQLstr)
SQLFields = ""
SQLValues = ""
For each frmItem in Request.Form
SQLFields = SQLFields & ", " & intNumItems
SQLValues = SQLValues & ", '" & Request.Form(intNumItems) & "'"
Next
SQLFields = mid(SQLFields, 3)
SQLValues = mid(SQLValues, 3)
SQLstr = "INSERT INTO Standards (" & SQLFields & ") VALUES (" & values
& ")"
objconn.execute(SQLstr)
rstemp.close
set rstemp=nothing
objconn.close
set objconn = nothing
%>
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Thu, 26 Jul 2001 15:43:57 -0400
|
|
The reason for that is because you are trying to execute the SQL string
before it has even been created. Also note that a recordset will not
be
returned when doing an INSERT, so get rid of the unused variables. And
I think your objConn.Open string is malformed, so that will be your
next
error. Are you trying to open an ODBC connection, or an OLE DB
connection?
Try this instead (watch out for those 3D and 20 things):
You'll still need to fix the Open command.
<%
' Declare variables
dim SQLFields, SQLValues, SQLstr, objConn
SQLFields =3D ""
SQLValues =3D ""
' Create strings for use in SQL Insert
For each frmItem in Request.Form
SQLFields =3D SQLFields & ", " & frmItem
SQLValues =3D SQLValues & ", '" & Request.Form(frmItem) & "'"
Next
' Remove the extra comma and space at the beginning
SQLFields =3D mid(SQLFields, 3)
SQLValues =3D mid(SQLValues, 3)
' Create the SQL string
SQLstr =3D "INSERT INTO Standards (" & SQLFields & ") VALUES (" &
values &
")"
' Open a connection to the database
Set objConn =3D Server.CreateObject ("ADODB.Connection")
objConn.Open "testdata"
' Execute the query
objconn.execute(SQLstr)
' Close the connection
objconn.close
set objconn =3D nothing
%>
> -----Original Message-----
> From: Lan Chi Tran [mailto:lanchi1975@y...]
> Sent: Thursday, July 26, 2001 8:15 PM
> To: ASP Databases
> Subject: [asp_databases] Command text was not set for the command
> object.
>
>
> Hi Expert,
>
> I went back and changed all the =3D3D and =3D20 as you said and
> those errors
> really go away. Thanks for that. However, another error came up.
>
> Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'
>
> Command text was not set for the command object.
>
> /ASP_Modify/response_create_entries7.asp,
>
> *************************************************
> LINE (set rstemp=3DobjConn.execute(SQLstr))
> ******************************************
>
>
> <%
> dim objConn, rs, names, values, SQL, SQLstr, rstemp
>
> Set objConn =3D Server.CreateObject ("ADODB.Connection")
> objConn.Open "testdata"
> set rstemp=3DobjConn.execute(SQLstr)
>
> SQLFields =3D ""
> SQLValues =3D ""
>
> For each frmItem in Request.Form
> SQLFields =3D SQLFields & ", " & intNumItems
> SQLValues =3D SQLValues & ", '" & Request.Form(intNumItems) & "'"
> Next
>
> SQLFields =3D mid(SQLFields, 3)
> SQLValues =3D mid(SQLValues, 3)
>
> SQLstr =3D "INSERT INTO Standards (" & SQLFields & ") VALUES ("
> & values
> & ")"
>
>
> objconn.execute(SQLstr)
> rstemp.close
> set rstemp=3Dnothing
> objconn.close
> set objconn =3D nothing
> %>
>
>
Message #3 by "J House" <jesse@s...> on Thu, 26 Jul 2001 21:49:52
|
|
I don't think you need these lines in your code
set rstemp=objConn.execute(SQLstr)
rstemp.close
set rstemp=nothing
try commenting them out.
also for debugging I usually comment out my objconn.execute(SQLstr)
and Response.write my sql string just to make sure it is correct.
Message #4 by "Grant I" <giswim1@a...> on Thu, 26 Jul 2001 22:09:53
|
|
Try substituting
rstemp.Open SQLstr, objConn, , , adCmdText
for
set rstemp=objConn.execute(SQLstr)
> Hi Expert,
>
> I went back and changed all the =3D and =20 as you said and those errors
> really go away. Thanks for that. However, another error came up.
>
> Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'
>
> Command text was not set for the command object.
>
> /ASP_Modify/response_create_entries7.asp,
>
> *************************************************
> LINE (set rstemp=objConn.execute(SQLstr))
> ******************************************
>
>
> <%
> dim objConn, rs, names, values, SQL, SQLstr, rstemp
>
> Set objConn = Server.CreateObject ("ADODB.Connection")
> objConn.Open "testdata"
> set rstemp=objConn.execute(SQLstr)
>
> SQLFields = ""
> SQLValues = ""
>
> For each frmItem in Request.Form
> SQLFields = SQLFields & ", " & intNumItems
> SQLValues = SQLValues & ", '" & Request.Form(intNumItems) & "'"
> Next
>
> SQLFields = mid(SQLFields, 3)
> SQLValues = mid(SQLValues, 3)
>
> SQLstr = "INSERT INTO Standards (" & SQLFields & ") VALUES (" & values
> & ")"
>
>
> objconn.execute(SQLstr)
> rstemp.close
> set rstemp=nothing
> objconn.close
> set objconn = nothing
> %>
|
|
 |