Solved

TIME ISSUE

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

697 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