Solved

TIME ISSUE

Posted on 2011-09-20
4
237 Views
Last Modified: 2012-05-12
I have the following attched code.    Everything works fine including the date; however, the time always shows up as
12 AM.   How do I correct this to show the actual time entered in the e-mail?
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Net.Mail;

partial class _Default : System.Web.UI.Page
{


	protected void btnSubmit_Click(object sender, System.EventArgs e)
	{
		System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection();

		string myPath = null;
		myPath = Server.MapPath("database2.mdb");

		con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" + myPath + ";";
		System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();

		myCommand.CommandText = string.Format("INSERT INTO AOS([Dates],[Ship],[ArrTime],[InFlt],[History],[ETRDate],[ETRTime],[Station],[Reason1],[Status1],[Updated],[Reason2],[Parts],[ata],[etr]) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')", DateTime.Parse(dates.Text), ship.Text, ArrTime.Text, InFlt.Text, History.Text, DateTime.Parse(ETRdate.Text), ETRTime.Text, Station.Text, Reason1.Text,
		Status1.Text, Updated.Text, Reason2.Text, Parts.Text, ata.Text, ETR.Text);
		myCommand.Connection = con;
		con.Open();
		myCommand.ExecuteNonQuery();
		con.Close();

		//Send Email
		SmtpClient smtpClient = new SmtpClient();
		MailMessage message = new MailMessage();
		MailAddress fromAddress = new MailAddress("AOS_Report@laxpm.com");
		message.From = fromAddress;
		message.To.Add("mark.scherer@allegiantair.com");
		message.CC.Add("mark@laxpm.com");
		message.Bcc.Add("Mark@laxpm.com");


		message.Subject = "AOS EVENT - LAS/IFP";

		string palinBody = "Date: " + DateTime.Parse(dates.Text) + ", Ship: " + ship.Text + ", Station: " + Station.Text + ", Arrival Time: " + ArrTime.Text + ", Inbound Flt#: " + InFlt.Text + ", History/ODI/Event Ind: " + History.Text + ", ETR Date: " + DateTime.Parse(ETRdate.Text) + ", ETR Time: " + ETRTime.Text + ", AOS Reason (short): " + Reason1.Text + ", Current Status: " + Status1.Text + ", Entered By: " + Updated.Text + ", AOS Description Detail: " + Reason2.Text + ", Parts/Tooling Requirements: " + Parts.Text + "";



		AlternateView plainView = AlternateView.CreateAlternateViewFromString(palinBody, null, "text/plain");
		string htmlBody = "<font color=\"black\"><font face=\"arial\">Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + DateTime.Parse(dates.Text) + "<p>Ship:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + ship.Text + "<p>Station:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Station.Text + "<p>Arrival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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Reason1.Text + "<p>Current Status:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Status1.Text + "<p>Entered By:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Updated.Text + "<br><br><br>AOS Description Detail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Reason2.Text + "<br><br><br>Parts/Tooling Requirements:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp " + Parts.Text + "<br /><br />You can view the Home Page here: <a href=http://LAS.LAXPM.com>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LAS Home</a>";




		AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, "text/html");
		message.AlternateViews.Add(plainView);
		message.AlternateViews.Add(htmlView);
		message.Priority = MailPriority.High;
		smtpClient.Host = "mail.laxpm.com";
		smtpClient.Send(message);

		Response.Redirect("http://las.laxpm.com/Redirect.htm");


	}


	protected void Page_Load(object sender, System.EventArgs e)
	{


	}
	public _Default()
	{
		Load += Page_Load;
	}

}

Open in new window

0
Comment
Question by:BOEING39
4 Comments
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 166 total points
ID: 36571275
It seems dates variable is not declared... Or is it a label? Textbox?

Try to use something like DateTime.Now or DateTime.Now.ToString() or LongTDateString etc
0
 
LVL 13

Accepted Solution

by:
jonnidip earned 167 total points
ID: 36571939
Please take a look to this method to parse a string to date:
public static DateTime GetDateTime_From_String(String string_date, String format)
{
   return DateTime.ParseExact(string_date.Trim(), format, CultureInfo.InvariantCulture, DateTimeStyles.None);
}

Open in new window

If your textbox contains a date in format: "09/21/2011 08:50", then you can parse it to a DateTime object by executing this method and passing "MM/dd/yyyy HH:mm" as the format parameter.

Regards.
0
 
LVL 16

Assisted Solution

by:Easwaran Paramasivam
Easwaran Paramasivam earned 167 total points
ID: 36571994
0
 

Author Closing Comment

by:BOEING39
ID: 36582279
Utilized all the suggestions offered.   All information sent was usefull in the solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now