944,126 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 1903
  • ASP RSS
Nov 20th, 2007
0

Will this work

Expand Post »
Hi I am experimenting with VBScript and SQL and am unsure if the following code will actually work. I do not have access to IIS at present so I am unable to test it. I would be greatfull if anyone could just take a brief look at the code to see if the syntax is correct. Thanks
ASP Syntax (Toggle Plain Text)
  1. <%@Language = "VBScript" %>
  2. <%Option Explicit%>
  3. <!--#include virtual="/advobs.inc"-->
  4. <%
  5. Dim newDate
  6. Dim newTime
  7. Dim newMessage
  8. Dim objConn
  9. Dim sqlInsert
  10. Dim objRecordSet
  11.  
  12. Set objConn = Server.CreatObject("ADODB.Connection")
  13. objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};"&_"DBQ=C:/inetpub/wwwroot/feedBack.mdb"
  14. objConn.Open
  15.  
  16. newDate = Date()
  17. newTime = Time()
  18. newMessage = request.form("strMessage")
  19.  
  20. if newMessage <> "" then
  21. sqlInsert="INSERT INTO tblMessages(date,time,message) VALUES(newDate,newTime,newMessage)"
  22. end if
  23.  
  24. Set objRecordSet=Server.CreateObject("ADODB.Recordset")
  25. objRecordSet.Open "tblMessages", objConn,,,adCmdTable
  26.  
  27. Do while Not objRecordSet.EOF
  28. Response.Write"<B>" & objRs ("time") & "</B><BR>"
  29. Response.Write objRs("date") & "<BR>"
  30. Response.Write objRs ("message") & "<BR>"
  31. Response.Write "<p><hr></p>"
  32.  
  33. objRecordSet.MoveNext
  34. Loop
  35.  
  36. objRecordSet.Close
  37. Set objRecordSet = Nothing
  38.  
  39. objConn.Close
  40. Set objConn = Nothing
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
FallenPaladin is offline Offline
62 posts
since Oct 2007
Nov 21st, 2007
0

Re: Will this work

sorry the above code needs to be amended for the loop to read
ASP Syntax (Toggle Plain Text)
  1. Do while Not objRecordSet.EOF
  2. Response.Write"<B>" & objRecordSet ("time") & "</B><BR>"
  3. Response.Write objRecordSet("date") & "<BR>"
  4. Response.Write objRecordSet ("message") & "<BR>"
  5. Response.Write "<p><hr></p>"
  6.  
  7. objRecordSet.MoveNext
  8. Loop
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
FallenPaladin is offline Offline
62 posts
since Oct 2007
Nov 28th, 2007
0

Re: Will this work

Here is the edited code and the reasons why:
ASP Syntax (Toggle Plain Text)
  1. <%@Language = "VBScript" %>
  2. <%Option Explicit%>
  3. <!--#include virtual="/advobs.inc"-->
  4. <%
  5. Dim newDate
  6. Dim newTime
  7. Dim newMessage
  8. Dim objConn
  9. Dim sqlInsert
  10. Dim objRecordSet
  11. ' Added below for SQL statement below
  12. Dim strSQL
  13.  
  14. Set objConn = Server.CreatObject("ADODB.Connection")
  15. objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};"&_"DBQ=C:/inetpub/wwwroot/feedBack.mdb"
  16. objConn.Open
  17.  
  18. 'newDate = Date()
  19. 'newTime = Time()
  20. 'Not needed as below. If this doesn't work (the current_timestamp), you can always use the following line and substitute it in below:
  21. 'newDateTime = now()
  22. newMessage = Trim(Request.Form("strMessage"))
  23. ' You should always trim variables coming in to lose beginning or trailing white spaces
  24.  
  25. if newMessage <> "" then
  26. sqlInsert="INSERT INTO tblMessages(datecreated,message) VALUES(CURRENT_TIMESTAMP,newMessage)"
  27. end if
  28.  
  29. ' Great thing about SQL, you can automatically put the date and time inside the database without having to code it in. You can set this to be default on your database, or do it from the SQL query. Change the date and time columns on your database to one. And also realize that date is probably a protected word in SQL. Use something more suitable like, datecreated.
  30.  
  31. Set objRecordSet=Server.CreateObject("ADODB.Recordset")
  32.  
  33. ' You should never open the entire table like that, even if that works.. Use a select statement.
  34.  
  35. strSQL = "SELECT * FROM tblMessages"
  36. objRecordSet.Open strSQL, objConn, adCmdTable
  37.  
  38. ' Another way to do the below line is
  39. 'Do Until objRecordSet.EOF
  40. ' But what you have is fine.
  41. Do while Not objRecordSet.EOF
  42. Response.Write"<B>" & FormatDateTime(objRs .fields("datecreated"),3) & "</B><BR>"
  43. Response.Write FormatDateTime(objRs("datecreated"),2) & "<BR>"
  44. Response.Write objRs.fields("message") & "<BR>"
  45. Response.Write "<p><hr></p>"
  46.  
  47. objRecordSet.MoveNext
  48. Loop
  49.  
  50. ' What the formatdatetime does is take the value and format what you want out of it. there are many ways to do this. the 2 after the value just creates time as 00:00:00 PM/AM, the 3 means 00/00/0000 format.
  51. ' Also remember that whenever you are dealing with more than one row, you need to put the recordsetname.fields attribute above.
  52.  
  53. objRecordSet.Close
  54. Set objRecordSet = Nothing
  55.  
  56. objConn.Close
  57. Set objConn = Nothing
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Nov 30th, 2007
0

Re: Will this work

Thank you for the reply it has been very helpful.

Jon
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
FallenPaladin is offline Offline
62 posts
since Oct 2007
Dec 12th, 2007
0

Re: Will this work

ya

working
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vasanthiraajan is offline Offline
1 posts
since Dec 2007
Dec 12th, 2007
0

Re: Will this work

glad to hear it!
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Dec 12th, 2007
0

Re: Will this work

So you know, if you are using a DATETIME field in your SQL database, you use the CURRENT_TIMESTAMP to get the current date and time. If you are using just date, use CURDATE(). When retrieving your information out of your database, especially for dates, you can do it this way:

DATE_FORMAT(datecreated, '%m/%d/%Y')

this will pull something out of your datetime or date column as: 2/7/2007

A full list on what you can do is here:
http://dev.mysql.com/doc/mysql/en/da...functions.html

Oh, and please mark the question as solved above the bottom banner on the page.
Last edited by SheSaidImaPregy; Dec 12th, 2007 at 11:22 am.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Extract cell value from Excel and import data via email
Next Thread in ASP Forum Timeline: File Upload in MySQL Database with ASP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC