Solved

TIME ISSUE

Posted on 2011-09-20
4
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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