Link to home
Start Free TrialLog in
Avatar of sporfex
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.CreateObject("ADODB.connection")
remoteconn.Open "Provider=SQLOLEDB.1;Driver={SQL  Server};SERVER=madeleine;DATABASE=Intranet;UID=sa;PWD=;"



Datum = trim(Request.Form("MyTime"))  
Rubrik = trim(Request.Form("MyRubrik"))
Text = trim(Request.Form("MyText"))
Avdelning = trim(Request.Form("MyDepartment"))

remoteconn.execute "insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('" & MyTime & "','" & MyRubrik & "','" & MyText & "','" & MyDepartment & "')"

%>

No error messages.
Avatar of sporfex
sporfex

ASKER

I think it sends the date field 'Datum' as 1900-01-01 all the time and the other fields are empty.
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.

?
Avatar of Paul Maker
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
if you want to enter a date into sql server use convert

i.e.

date_col = CONVERT(datetime,"&Request("date_item")&",103)

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("MyDepartment")),"'","''")

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 & "')"
Avatar of sporfex

ASKER

Response.write are

insert into Nyheter (Datum, Rubrik, Text, Avdelning) values ('','','','')

Notheing is posted...hmm
Avatar of sporfex

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
did any of that info help you sporfex?
Avatar of sporfex

ASKER

I'm home now but will try it first thing tomorrow.
Avatar of sporfex

ASKER

John844 and others.
Have change the code to yours, still the same problem.

Response.write =

INSERT Nyheter (Datum, Rubrik, Information, Avdelning) VALUES ('','','','')
Avatar of sporfex

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?
ASKER CERTIFIED SOLUTION
Avatar of John844
John844

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial