Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005

    Unanswered: Now() = Date and a Time

    I'm working with an ASP.Net web site that uses Access for a DB. I have a simple message board on this site and would like to automatically load the system date and the time in when a message is added.

    Are there functions in Access to do this? In MySQL I use the Now().

    Below is the error that I'm getting when trying to set these functions when adding a message to my message table in my DB.
    Compiler Error Message: CS1002: ; expected
    Source Error:
    Line 25: 		string sql;
    Line 26: 		sql = "INSERT INTO Message (email, messageDate, messageTime, messageTitle, message) VALUES " +
    Line 27: 				"('" + email + "', '" + Date$ + "', '" + Time$ + "', '" + messageTitle + "', '" + message + "')";
    Line 28: 		
    Line 29:
    I found this site here

    And used Time$ and Date$, but get the error above.

    Bob W.

  2. #2
    Join Date
    Feb 2004
    One Flump in One Place
    Hi Bob

    This isn't an access question. You are building up a literal string. Is that JScript? If so you need to use the JScript functions for date and time as you are concatenating those values into the string.

    To answer the question literally, Now(), Date() and Time() are the Access functions.

    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Apr 2005
    The code above was just an SQL statement to add a message to the message table in a database. It's using ASP.Net and C# to work with the DB.
    I wanted to pull the system date for the date and times and then eliminate the text box options in the form below for those two entries, letting the system enter the system date at time of adding a message. The user would then not have to deal with it.

    Here is the code for the page:
    <%@ Page Language="C#" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Register TagPrefix="MMenu" TagName="Menu" src="Menu.ascx" %>
    <script runat="server">
    void Page_Load(Object o, EventArgs e)
    	if (IsPostBack)
    		// create and open connection
    		string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Message1.mdb");
    		OleDbConnection conn = new OleDbConnection(connStr);
    		// get form values
    		string email, messageDate, messageTime, messageTitle, message;  //messageNum,
    		//messageNum = messageNumField.Value;
    		email = emailField.Value;
    		messageDate = messageDateField.Value;
    		messageTime = messageTimeField.Value;
    		messageTitle = messageTitleField.Value;
    		message = messageField.Value;
    		// build sql
    		string sql;
    		sql = "INSERT INTO Message (email, messageDate, messageTime, messageTitle, message) VALUES " +
    				"('" + email + "', '" + messageDate + "', '" + messageTime + "', '" + messageTitle + "', '" + message + "')";
    		// create and run command
    		OleDbCommand cmd = new OleDbCommand(sql, conn);
    		int recordsAffected;
    		recordsAffected = cmd.ExecuteNonQuery();
    		//Print out sql
    		// show records affected
    		message2.InnerHtml = "Message Added Successfully.<br>";
    		message1.InnerHtml = recordsAffected.ToString();
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <MMenu:Menu runat="server" />
    <span id="message1" runat="server"></span>
    <span id="message2" runat="server"></span>
    <p><b>Add a Users Message</b></p>
    <form runat="server" action="updateMessageForm.aspx" >
    <!--<input id="messageNumField" runat="server" type="hidden">-->
    email:<input id="emailField" runat="server">
    date:<input id="messageDateField" runat="server">
    time:<input id="messageTimeField" runat="server">
    Message Title:<input id="messageTitleField" runat="server">
    Message:<input id="messageField" runat="server">
    <input type="submit" runat="server">

  4. #4
    Join Date
    Feb 2004
    One Flump in One Place
    You are still building a literal string though Bob. Also, presuming the messageDate field in the table is datetime you need to wrap # around the value instead of '.

    Could you post the sql string that you are executing please? Alternatively, you could simply change the default value of the Access fields to Date() and Time() respectively.
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts