Solved

TIME ISSUE

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
visual Basic Net vs c# net 8 56
Windows Service with UDP 2 28
Duplicate a row 2 33
ASP.NET Web API or ASP.NET Core MVC? 3 32
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

11 Experts available now in Live!

Get 1:1 Help Now