|
 |
asp_databases thread: HELP!!! INSERT/UPDATE (ASP). YOUR HELP IS VERY APPRECIATED!!!
Message #1 by "Lan Chi Tran" <lanchi1975@y...> on Thu, 26 Jul 2001 18:50:16
|
|
First of all, thank you very much for your solutions. You just don't know
how happy and surprise I am since this is my first time I post my question
on this site in private speaking as well as on the internet in general.
When I first posted, I was very nervous and don't really know how long I
would hear from you. Maybe tomorrow, the next day or forever......Thanks
for your quick responses.
Get back to your solution. Enclosing are my codes and the errors that I
have encountered while running it.
**************************
create_entries.asp
*************************
<%
Dim objConn, myDSN, SQL
myDSN="DSN=testdata;UID=sa"
set objConn=server.createobject("adodb.connection")
objConn.open myDSN
SQL="Select * from STANDARDS"
set rstemp=objConn.execute(SQL)
%>
<table border=1 CELLPADDING='2' BGCOLOR='#D5D0DF'>
<H3>Please fill out this form.</H3><tr>
<%
for each fieldname in rstemp.fields%>
<TR><TD><b><%=fieldname.name%></TD></b><TD><INPUT TYPE=TEXT name=<%
=fieldname.name %>></TD></TD></TR>
<% next %>
</table>
<%
rstemp.close
set rstemp=nothing
objConn.close
set objConn=nothing
%>
<P>
<TR><TD><INPUT TYPE=SUBMIT VALUE=CREATE ENTRIES></TD>
<TD><INPUT TYPE=RESET VALUE=RESET></TD>
</TR>
</form></TABLE>
*********************************
response_create_entries6.asp
*********************************
<%
dim objConn
dim rs
dim names, values, SQL
dim strsql
Set objConn = Server.CreateObject ("ADODB.Connection")
objConn.Open "testdata"
set rstemp=objConn.execute(SQL)
' Get the names
names = ""
for each f in rstemp.fields
names = names & ", " & f.name
next
names = mid(names,3)
' Now do the same for values (but strings must
' be in single quotes and dates must be in hashes
values = ""
for each f in rstemp.fields
select case f.type ' look this up, I'm guessing now
case adVarChar, adChar ' look this up
' It's a string value, so use quotes
values = values & ", '" & request.form(f.name) & "'"
case adInteger ' look this up
values = values & ", " & request.form(f.name)
case adDate ' look this up
values = values & ", #" & request.form(f.name) & "#"
case else
' Other type, throw it away since I don't know what to do with it
' and raise an error maybe
end select
next
values = mid(values,3)
SQL = "INSERT INTO Customers (" & names & ") VALUES " & values
objconn.execute(SQL)
rstemp.close
set rstemp=nothing
objconn.close
set objconn = nothing
%>
*******************************
ERRORS---If I comment out this line (set rstemp=objConn.execute(SQL))
*********************************
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/ASP_Modify/response_create_entries6.asp, line 35
THIS IS LINE 35 (for each f in rstemp.fields)
**************************************************
******************************
ERRORS---If I don't comment out this line (set rstemp=objConn.execute(SQL))
*********************************
Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'
Command text was not set for the command object.
/ASP_Modify/response_create_entries6.asp, line 30
THIS IS LINE 30 (set rstemp=objConn.execute(SQL))
**************************************************
Message #2 by "Lan Chi Tran" <lanchi1975@y...> on Thu, 26 Jul 2001 18:57:13
|
|
I tested using the second response. This is what I got. Please help
since I have no clue on your code. Thanks in advance.
What are the =20 and =3D ""?????? It produced these errors while I am
trying to run it.
********************
create_entries.asp
********************
<%
Dim objConn
myDSN="DSN=testdata;UID=sa"
set objConn=server.createobject("adodb.connection")
objConn.open myDSN
mySQL="Select * from STANDARDS"
set rstemp=objConn.execute(mySQL)
%>
<table border=1 CELLPADDING='2' BGCOLOR='#D5D0DF'>
<H3>Please fill out this form.</H3><tr>
<%
for each fieldname in rstemp.fields%>
<TR><TD><b><%=fieldname.name%></TD></b><TD><INPUT TYPE=TEXT name=<%
=fieldname.name %>></TD></TD></TR>
<% next %>
</table>
<%
rstemp.close
set rstemp=nothing
objConn.close
set objConn=nothing
%>
<P>
<TR><TD><INPUT TYPE=SUBMIT VALUE=CREATE ENTRIES></TD>
<TD><INPUT TYPE=RESET VALUE=RESET></TD>
</TR>
</form></TABLE>
****************************
response_create_entries.asp
*****************************
<%
columns =3D ""
dim objconn
dim rs
dim strsql
Set objConn = Server.CreateObject ("ADODB.Connection")
objConn.Open "testdata"
for each fieldname in rstemp.fields
WHILE NOT rstemp.EOF
IF NOT rstemp.EOF THEN
columns =3D columns & fieldname.name & ", "
END IF
WEND
next
colLen=3D LEN(columns) - 2
columns =3D TRIM(LEFT(columns, colLen))
values =3D ""
FOR EACH fieldname IN rstemp.fields
WHILE NOT rstemp.EOF
IF NOT rstemp.EOF THEN
values =3D values & "'" & fieldname.Value & "', "
END IF
WEND
NEXT
valLen =3D LEN(values) - 2
values =3D TRIM(LEFT(values, valLen))
strSQL =3D "INSERT INTO Standards(" & columns & ") VALUES (" & values & ")"
objconn.execute(strSQL)
objconn.close
set objconn = nothing
%>
*************************
ERROR
***************************
Microsoft VBScript compilation error '800a0400'
Expected statement
/ASP_Modify/response_create_entries5.asp, line 2
^
************************
Message #3 by "Grant I" <giswim1@a...> on Thu, 26 Jul 2001 19:45:50
|
|
Didn't look at your code yet, but I can tell you this right away. Ignore
the =20 and =3D that appear in some people's posts. This is a result of
something with their mail client. =3D just means = so if you see
1 + 1 =3D 2
it means
1 + 1 = 2
And =20 means new line so...
<%
Response.Write("Hi there")
%>
should be...
<%
Response.Write("Hi there")
%>
I'll look through your code now, but go back and change all =3D to = and
just delete all
HTH
Grant
> I tested using the second response. This is what I got. Please help
> since I have no clue on your code. Thanks in advance.
>
> What are the =20 and =3D ""?????? It produced these errors while I am
> trying to run it.
>
> ********************
> create_entries.asp
> ********************
> <%
> Dim objConn
> myDSN="DSN=testdata;UID=sa"
> set objConn=server.createobject("adodb.connection")
> objConn.open myDSN
> mySQL="Select * from STANDARDS"
> set rstemp=objConn.execute(mySQL)
> %>
> <table border=1 CELLPADDING='2' BGCOLOR='#D5D0DF'>
> <H3>Please fill out this form.</H3><tr>
> <%
> for each fieldname in rstemp.fields%>
> <TR><TD><b><%=fieldname.name%></TD></b><TD><INPUT TYPE=TEXT name=<%
> =fieldname.name %>></TD></TD></TR>
> <% next %>
> </table>
> <%
> rstemp.close
> set rstemp=nothing
> objConn.close
> set objConn=nothing
> %>
> <P>
> <TR><TD><INPUT TYPE=SUBMIT VALUE=CREATE ENTRIES></TD>
> <TD><INPUT TYPE=RESET VALUE=RESET></TD>
> </TR>
> </form></TABLE>
> ****************************
> response_create_entries.asp
> *****************************
> <%
> columns =3D ""
> dim objconn
> dim rs
>
> dim strsql
>
> Set objConn = Server.CreateObject ("ADODB.Connection")
> objConn.Open "testdata"
>
> for each fieldname in rstemp.fields
> WHILE NOT rstemp.EOF
> IF NOT rstemp.EOF THEN
> columns =3D columns & fieldname.name & ", "
> END IF
> WEND
> next
>
> colLen=3D LEN(columns) - 2
> columns =3D TRIM(LEFT(columns, colLen))
>
> values =3D ""
> FOR EACH fieldname IN rstemp.fields
> WHILE NOT rstemp.EOF
> IF NOT rstemp.EOF THEN
> values =3D values & "'" & fieldname.Value & "', "
> END IF
> WEND
> NEXT
>
> valLen =3D LEN(values) - 2
> values =3D TRIM(LEFT(values, valLen))
>
> strSQL =3D "INSERT INTO Standards(" & columns & ") VALUES (" & values
& ")"
> objconn.execute(strSQL)
> objconn.close
> set objconn = nothing
>
> %>
> *************************
> ERROR
> ***************************
> Microsoft VBScript compilation error '800a0400'
>
> Expected statement
>
> /ASP_Modify/response_create_entries5.asp, line 2
>
>
> ^
> ************************
>
Message #4 by Steve Carter <Steve.Carter@t...> on Fri, 27 Jul 2001 10:21:40 +0100
|
|
=20 is space.
=0d is LF
=0a is CR
so =0a=0d is end of line in winDOS
> -----Original Message-----
> From: Grant I [mailto:giswim1@a...]
> Sent: 26 July 2001 20:46
> And =20 means new line so...
> <%
|
|
 |