Little Help....

This is a discussion on "Little Help...." within the Classic ASP section. This forum, and the thread "Little Help.... are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 5th, 2004, 09:57
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Little Help....

Ok, this is what I have gotten so far. I am working on the Registration form, and I know, I haven't even gotten this far without a problem. here is my code.

Code: Select all
<%
Set connectionToDatabase=Server.CreateObject("ADODB.Connection")
connectionToDatabase.ConnectionTimeout=60
connectionToDatabase.Open "DSN=Mydatabase"

Set recordSet =Server.CreateObject("ADODB.Recordset")
recordSet.Open "SELECT * FROM List" ,connectionToDatabase, 1,2

recordSet.AddNew
recordSet("First")=Request.Form("First")
recordSet("Last")=Request.Form("Last")
recordSet("User")=Request.Form("User")
recordSet("Password")=Request.Form("Password")
recordSet("Address")=Request.Form("Address")
recordSet("City")=Request.Form("City")
recordSet("State")=Request.Form("State")
recordSet("Country")=Request.Form("Country")
recordSet("Email")=Request.Form("Email")
recordSet("Date")=Request.Form("Date")
recordSet.Update

Do while Not recordSet.EOF
		recordSet.MoveNext
Loop

connectionToDatabase.close
Set connectionToDatabase=Nothing
%>
And I am getting this error.
Code: Select all
Provider error '80020005' 

Type mismatch. 

/ASPtests/Submit.asp, line 28
The problem is that it actually matches the content of the Database exactly and that of the form. So I am confused as to why I am getting this error. line 28 in the code is actually this recordSet("Date")=Request.Form("Date")

A couple of other things i wanted to ask about... Is there a better/Easier way of connecting to a database? Cause this way works fine and all, but I can only use 1 DSN with my current host.

  #2 (permalink)  
Old Apr 5th, 2004, 11:48
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
I would never do it like that, but whatever floats your boat...

as you know, string, number and date are all different data types, if you have a field in your database called "Date", and it is of Date/Time datatype, then you need to convert the string (Request.Form("Date")) into date format using the CDate() function.
  #3 (permalink)  
Old Apr 5th, 2004, 15:33
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
...but you'll need to make sure you validate the input otherwise you'll get an error with CDate()

Run the date through a function like this before you insert it:

Code: Select all
Function FixDBDates(dtmDate)

  If dtmDate = "" Then
    FixDBDates = dtmDate
    Exit Function
  End If

  Dim dtmTmp
  
  dtmTmp = Day(dtmDate) & "/" & MonthName(Month(dtmDate)) & "/" & Year(dtmDate) & " " & Hour(dtmDate) & ":" & Minute(dtmDate) & ":" & second(dtmDate)
  
  FixDBDates= dtmTmp
  
End Function

...

recordSet("Date") = FixDBDates(Request.Form("Date"))
If you gave this function 20/11/2004 it would give you 20/december/2004
  #4 (permalink)  
Old Apr 5th, 2004, 18:14
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
You need to delimit the date to put it in a date field. For Access the delimiter is # so you'd do:

recordSet("Date")= "#" & Request.Form("Date")& "#"
  #5 (permalink)  
Old Apr 5th, 2004, 19:50
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
It's ok Smokie... Like I have said before, Im very new at this, and this site is not for anyone, it's just to help me learn what I am doing. Cause you never get anything accomplished without practice :wink:.
  #6 (permalink)  
Old Apr 5th, 2004, 20:51
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Oh, I didn't see the end of your post with the questions. First , you can use a DSN-less connection. They're faster and don't need anything setup on the host.

Personally "connectionToDatabase" is a really long thing to keep typing even if it's very easy to read. I always just use "con" or "objCon" - just a cosmetic thing where you'll make less typos. Same with recordset... rs or objRs.

Finally I almost never use AddNew. I just add the whole record with one line using an INSERT INTO sql statement.
  #7 (permalink)  
Old Apr 6th, 2004, 08:29
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
Always use Option Explicit to stop typos Catalyst :razz:

Sorry for forgetting to wrap the date in hashes...haha, or pound signs if your American!
  #8 (permalink)  
Old Apr 6th, 2004, 09:15
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
well Im american and I call them hashes... Hrmm Am I just stupid? Well It's still not working even by taking all of yall's advice. So I think I am just going to go further and use some other methods of doing it. I thought this was the best way to do it, but I guess I might use something else.

Ok, Like I said I am a BIG NOOB so this is me trying to learn and is not for any real purpose besides that, but if I am using Access to do my database, can I still use SQL Statements? If so, then i can do this easily with the following.

Code: Select all
sqlStatement="INSERT INTO List(First,Last,User) Values ("& frmFirst & ",'" & frmLast &"'," & frmUser & ")"

Set recordSet=connectionToDatabase.Execute(sqlStatement)

connectionToDatabase.Close
Set connectionToDatabase=Nothing
%>
  #9 (permalink)  
Old Apr 6th, 2004, 09:23
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
The Hash pound thing came from something I read regarding C# (C Sharp), i'm sure someone somewhere will know what I was talking about!

And yes, you can use SQL INSERT statements for access.
  #10 (permalink)  
Old Apr 6th, 2004, 09:26
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
YAY!!! Well that's going to save me about a BILLION hours of strenuous work. :wink: . I just thought that SQL worked with MYSQL for some strange reason.. Guess cause in my book they use SQL statemenst with MYSQL databases only, and use the Recordsets with Access. Guess I read too much into it, lol.
  #11 (permalink)  
Old Apr 6th, 2004, 09:36
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
your missing some single quotes:

sqlStatement="INSERT INTO List(First,Last,User) Values ('"& frmFirst & "','" & frmLast &"','" & frmUser & "')"
  #12 (permalink)  
Old Apr 6th, 2004, 09:43
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
ohh.. lol, no wonder it wasn't working.. I almost posted back on here again.. Thanks for saving me some time there Smokie :wink:
  #13 (permalink)  
Old Apr 6th, 2004, 10:18
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
for future reference, if you are inserting a string, it must be wrapped in single quotes, a number doesnt need any quotes and a date needs #'s (or single quotes if you are using MS SQL Server)
  #14 (permalink)  
Old Apr 6th, 2004, 10:51
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
What knowledge....I can only dream of being as clever as Smokie
  #15 (permalink)  
Old Apr 6th, 2004, 12:36
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
one day my son, your time will come...

  #16 (permalink)  
Old Apr 6th, 2004, 18:44
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Also, be careful about using reserved words for field names, sometimes things like 'Date' or 'Name' used as a field name will cause an error and drive you crazy.
  #17 (permalink)  
Old Apr 8th, 2004, 14:19
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
I'm glad Court Jester's asking these questions, I'm learning alot from just reading all of this... thanks guys.
  #18 (permalink)  
Old Apr 8th, 2004, 19:03
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Cata... I got soooo soo mad couldn't figure out what I was doing wrong. Forgot Date is a reserved word. haha.. Im going to rip that page out of my book and glue it to my forehead :wink:
  #19 (permalink)  
Old Apr 8th, 2004, 20:25
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Glad to help.
Closed Thread

Tags
little, help

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 22:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43