Will this work

Reply

Join Date: Oct 2007
Posts: 48
Reputation: FallenPaladin is an unknown quantity at this point 
Solved Threads: 0
FallenPaladin FallenPaladin is offline Offline
Light Poster

Will this work

 
0
  #1
Nov 20th, 2007
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
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 48
Reputation: FallenPaladin is an unknown quantity at this point 
Solved Threads: 0
FallenPaladin FallenPaladin is offline Offline
Light Poster

Re: Will this work

 
0
  #2
Nov 21st, 2007
sorry the above code needs to be amended for the loop to read
  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Will this work

 
0
  #3
Nov 28th, 2007
Here is the edited code and the reasons why:
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 48
Reputation: FallenPaladin is an unknown quantity at this point 
Solved Threads: 0
FallenPaladin FallenPaladin is offline Offline
Light Poster

Re: Will this work

 
0
  #4
Nov 30th, 2007
Thank you for the reply it has been very helpful.

Jon
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1
Reputation: vasanthiraajan is an unknown quantity at this point 
Solved Threads: 0
vasanthiraajan vasanthiraajan is offline Offline
Newbie Poster

Re: Will this work

 
0
  #5
Dec 12th, 2007
ya

working
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Will this work

 
0
  #6
Dec 12th, 2007
glad to hear it!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Will this work

 
0
  #7
Dec 12th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC