sporfex
asked on
store data in SQL 7 table
Hi.
The code below doesn't work. What is wrong?
<%@ Language=VBScript %>
<%
'************************* *
'* Connection starts here *
'************************* *
set remoteconn=server.CreateOb ject("ADOD B.connecti on")
remoteconn.Open "Provider=SQLOLEDB.1;Drive r={SQL Server};SERVER=madeleine;D ATABASE=In tranet;UID =sa;PWD=;"
Datum = trim(Request.Form("MyTime" ))
Rubrik = trim(Request.Form("MyRubri k"))
Text = trim(Request.Form("MyText" ))
Avdelning = trim(Request.Form("MyDepar tment"))
remoteconn.execute "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','" & MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
%>
No error messages.
The code below doesn't work. What is wrong?
<%@ Language=VBScript %>
<%
'*************************
'* Connection starts here *
'*************************
set remoteconn=server.CreateOb
remoteconn.Open "Provider=SQLOLEDB.1;Drive
Datum = trim(Request.Form("MyTime"
Rubrik = trim(Request.Form("MyRubri
Text = trim(Request.Form("MyText"
Avdelning = trim(Request.Form("MyDepar
remoteconn.execute "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','" & MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
%>
No error messages.
do a response.write "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
to see what the sql statment is being produced as, maybe a non null is null, for example are the names of the request(form_item) correct
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
to see what the sql statment is being produced as, maybe a non null is null, for example are the names of the request(form_item) correct
if you want to enter a date into sql server use convert
i.e.
date_col = CONVERT(datetime,"&Request ("date_ite m")&",103)
it must be formatted correctly, i.e. "09/09/2001"
i.e.
date_col = CONVERT(datetime,"&Request
it must be formatted correctly, i.e. "09/09/2001"
some things I noticed.
1. you need to handle single quotes in the data
2. You don't need "into"
3. Text might be a keyword, add []
Datum = replace(trim(Request.Form( "MyTime")) ,"'","''")
Rubrik = replace(trim(Request.Form( "MyRubrik" )),"'","'' ")
Text = replace(trim(Request.Form( "MyText")) ,"'","''")
Avdelning = replace(trim(Request.Form( "MyDepartm ent")),"'" ,"''")
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
John
1. you need to handle single quotes in the data
2. You don't need "into"
3. Text might be a keyword, add []
Datum = replace(trim(Request.Form(
Rubrik = replace(trim(Request.Form(
Text = replace(trim(Request.Form(
Avdelning = replace(trim(Request.Form(
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
John
and it looks like you are not putting the values gathered in four statements into the insert statement...
shouldn't this statement
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
be changed to
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & Datum & "','"
& Rubrik & "','" & Text & "','" & Avdelning & "')"
shouldn't this statement
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & MyTime & "','"
& MyRubrik & "','" & MyText & "','" & MyDepartment & "')"
be changed to
remoteconn.execute "INSERT Nyheter (Datum, Rubrik, [Text], Avdelning) VALUES ('" & Datum & "','"
& Rubrik & "','" & Text & "','" & Avdelning & "')"
ASKER
Response.write are
insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('','','','')
Notheing is posted...hmm
insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('','','','')
Notheing is posted...hmm
ASKER
I noticed one thing myself. 'Text' isn't a good name for an object I guess?
try my last post. I think that you are using different variable names in your statement. you set the value into Datum and then use MyTime in your insert statement.....
John
John
did any of that info help you sporfex?
ASKER
I'm home now but will try it first thing tomorrow.
ASKER
John844 and others.
Have change the code to yours, still the same problem.
Response.write =
INSERT Nyheter (Datum, Rubrik, Information, Avdelning) VALUES ('','','','')
Have change the code to yours, still the same problem.
Response.write =
INSERT Nyheter (Datum, Rubrik, Information, Avdelning) VALUES ('','','','')
ASKER
I have found the errors. Stupid errors.
Two of my text fields in the form was disabled.
How can I disable the fields and still send the data?
Two of my text fields in the form was disabled.
How can I disable the fields and still send the data?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So the connection shoul be okey? Something else with the code. Probably the date?
Datum is set to datetime on the SQL 7 server table.
?