Solved

TIME ISSUE

Posted on 2011-09-20
4
238 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Comparing String Arrays. 5 40
Set value of dynamically created checkboxlist 2 34
Reference issues in Visual Studio 3 30
Release Dynamically Allocated Memory in C# 3 26
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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