PDA

View Full Version : updating from question


gcapp
10-08-2002, 06:10 PM
Can someone answer this for me?

I have a database and I am trying to update a record in it.

The datatype for fields Start_Date and End_Date are Date/Time.

I have this code and I get a type mismatch error on the lines in bold.

If Request.Form("btnUpdate") = "Update" Then

RecordSet.Fields("EventID") = Request.Form("intEventID")
RecordSet.Fields("Event_Name") = Request.Form("txtEvent_Name")
RecordSet.Fields("Location") = Request.Form("txtLocation")
RecordSet.Fields("City") = Request.Form("txtCity")
RecordSet.Fields("State") = Request.Form("txtState")
RecordSet.Fields("Zip_Code") = Request.Form("txtZip_Code")
RecordSet.Fields("Description") = Request.Form("txtDescription")
RecordSet.Fields("Start_Date") = Request.Form("txtStart_Date")
RecordSet.Fields("End_Date") = Request.Form("txtEnd_Date")
RecordSet.Fields("Time") = Request.Form("txtTime")
RecordSet.Fields("Phone") = Request.Form("txtPhone")
RecordSet.Fields("Website") = Request.Form("txtWebsite")
RecordSet.Fields("Email") = Request.Form("txtEmail")
RecordSet.Fields("event_image") = Request.Form("txtevent_image")
RecordSet.Update
Updated = "True"


So my question is what should I change the ("txtStart_Date") and ("txtEnd_Date") to??

Is it "intStart_Date"?

I'm not sure what to change the txt part to.

Help please!!

Gary

allida77
10-08-2002, 06:30 PM
You can try CDate() around the form fields.

Are one of those fields empty when you are updating? I always have to check to see if there is a value or else my db(db2) will throw an error at me when dealing with dates.

gcapp
10-09-2002, 12:00 AM
Allida77,
I'm getting an error that I can't figure out. I am new to asp so bear with me.

I put the last code you sent me into my page. What this page is supposed to do is add a record to my database. Now I have the exact same page code for another database that I update and it works fine. Here, I can't figure it out.

The code is here:
<%
Dim Conn, cmdDC, RecordSet
Dim RecordToEdit, Updated
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open UPLOAD_DSN

Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = Conn

SQL = "SELECT * FROM Events ORDER BY Start_Date"

cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.RecordSet")

'-- Cursor Type, Lock Type

'-- ForwardOnly 0 - ReadOnly 1
'-- KeySet 1 - Pessimistic 2
'-- Dynamic 2 - Optimistic 3
'-- Static 3 - BatchOptimistic 4

RecordSet.Open cmdDC, , 0, 2




If Request.Form("btnAdd") = "Add" Then
RecordSet.AddNew

RecordSet.Fields("EventID") = Request.Form("intEventID")
RecordSet.Fields("Event_Name") = Request.Form("txtEvent_Name")
RecordSet.Fields("Location") = Request.Form("txtLocation")
RecordSet.Fields("City") = Request.Form("txtCity")
RecordSet.Fields("State") = Request.Form("txtState")
RecordSet.Fields("Zip_Code") = Request.Form("txtZip_Code")
RecordSet.Fields("Description") = Request.Form("txtDescription")
RecordSet.Fields("Start_Date") = Request.Form("CDateStart_Date")
RecordSet.Fields("End_Date") = Request.Form("CDateEnd_Date")
RecordSet.Fields("Time") = Request.Form("txtTime")
RecordSet.Fields("Phone") = Request.Form("txtPhone")
RecordSet.Fields("Website") = Request.Form("txtWebsite")
RecordSet.Fields("Email") = Request.Form("txtEmail")
RecordSet.Fields("event_image") = Request.Form("txtevent_image")

RecordSet.Update
Added= "True"

End If
%>


The error indicates that there is a syntax error in the INSERT INTO statement.

Well first I don't even see an INSERT INTO statement.

Do you see what the problem might be?

And I also have another problem with the Edit page. Obviously the edit page is supposed to allow me to edit a record. Well I get another error with this page except this one is a type mismatch error, which occurs at the bolded line in the code below:

If Request.Form("btnUpdate") = "Update" Then

RecordSet.Fields("EventID") = Request.Form("intEventID")
RecordSet.Fields("Event_Name") = Request.Form("txtEvent_Name")
RecordSet.Fields("Location") = Request.Form("txtLocation")
RecordSet.Fields("City") = Request.Form("txtCity")
RecordSet.Fields("State") = Request.Form("txtState")
RecordSet.Fields("Zip_Code") = Request.Form("txtZip_Code")
RecordSet.Fields("Description") = Request.Form("txtDescription")
RecordSet.Fields("Start_Date") = Request.Form("CDateStart_Date")
RecordSet.Fields("End_Date") = Request.Form("CDateEnd_Date")
RecordSet.Fields("Time") = Request.Form("txtTime")
RecordSet.Fields("Phone") = Request.Form("txtPhone")
RecordSet.Fields("Website") = Request.Form("txtWebsite")
RecordSet.Fields("Email") = Request.Form("txtEmail")
RecordSet.Fields("event_image") = Request.Form("txtevent_image")
RecordSet.Update
Updated = "True"

End If
%>


This is the Date/Time field that I asked about earlier.

If this is too difficult to grasp, I attached the three pages this all pertains to, View, Add and Edit and the information pertaining to the database I'm using.

I hope you or someone out there can help me.

Gary

allida77
10-09-2002, 01:13 PM
Your syntax should be:

CDate(Request.Form("Start_Date") )