rwheeler23
asked on
Visual Studio C# Date Formats
I have selected data and have placed in on the form. I cannot quite get the syntax for the date format correct. I want it to be short fomat MM/DD/YY. I have guides for the various formats but I cannot quite get the syntax correct for VS 2008 C#.
use DateTimeObject.ToShortDate String()
see the link:
use DateTimeObject.ToShortDate String()
use DateTimeObject.ToShortDate
see your duplicate link
ASKER
How do I enter the entire line? I tried several combinations of what is below and nothing works.
this.txtDateOfQuote.Text = this.txtDateOfQuote.ToShor tDateStrin g();
this.txtDateOfQuote.Text = this.txtDateOfQuote.ToShor
this.txtDateOfQuote.Text = new DateTime(this.txtDateOfQuo
this.txtDateOfQuote.Text = (new DateTime(this.txtDateOfQuo
ASKER
When I do this I get these two error messages.
Error 1 The best overloaded method match for 'System.DateTime.DateTime( long)' has some invalid arguments C:\VSProjects\ViewQuote\Vi ewQuote\Vi ewQuote.cs 67 41 ViewQuote
Error 2 Argument '1': cannot convert from 'string' to 'long' C:\VSProjects\ViewQuote\Vi ewQuote\Vi ewQuote.cs 67 54 ViewQuote
Error 1 The best overloaded method match for 'System.DateTime.DateTime(
Error 2 Argument '1': cannot convert from 'string' to 'long' C:\VSProjects\ViewQuote\Vi
Hi,
Try below code
txtDateOfQuote.Text = Convert.ToDateTime(txtDate OfQuote.Te xt).ToStri ng("MM/dd/ yy");
Try below code
txtDateOfQuote.Text = Convert.ToDateTime(txtDate
ASKER
This is strange. I insert this line, it builds successfully but when I execute the code, the screen on which this code belongs no longer appears. If I comment out this line it does appear.
Hi,
Are you getting any error when executing?
Are you getting any error when executing?
ASKER
I can see what is happening but I do not understand it. I can see the date on the screen in long format but by the time it gets to the code to convert it, the date field is blank. What am I missing here?
this.txtDateOfQuote.DataBi ndings.Add ("Text", QuoteHeaderDataSet.Tables[ "QuoteHead er"], "DATE_OF_QUOTE_OEQH");
if (txtDateOfQuote.Text != "" )
{
txtDateOfQuote.Text = Convert.ToDateTime(txtDate OfQuote.Te xt).ToStri ng("MM/dd/ yy");
}
this.txtDateOfQuote.DataBi
if (txtDateOfQuote.Text != "" )
{
txtDateOfQuote.Text = Convert.ToDateTime(txtDate
}
Hi,
What format of date you are getting before convert?
Can you post the exact date here?
What format of date you are getting before convert?
Can you post the exact date here?
ASKER
Here is the entire section of code. The date on this particular order is 12/28/09 12:00:00 AM.
I think I am still stuck in my old 'C' top down world. I have data for the header and data for the grid but I am using the same DataAdapter variable. As I said, I see the date on the screen but my code sees it as blank. Is my second use of DataAdapter wiping out the date?
I think I am still stuck in my old 'C' top down world. I have data for the header and data for the grid but I am using the same DataAdapter variable. As I said, I see the date on the screen but my code sees it as blank. Is my second use of DataAdapter wiping out the date?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;
using Microsoft.Dexterity.Shell;
namespace ViewQuote
{
public partial class ViewQuote : DexUIForm
{
public static string myAppName = "View Quote Program";
/* Setup SOP form so you can extract value off SOP_ENTRY form */
static SopEntryForm sopEntryForm = Dynamics.Forms.SopEntry;
static SopEntryForm.SopEntryWindow sopEntryWindow = sopEntryForm.SopEntry;
/* Setup SQL comnnections for Quote Header and Quote Detail */
private System.Data.SqlClient.SqlConnection qdConnection;
private System.Data.SqlClient.SqlConnection qhConnection;
private System.Data.DataSet QuoteHeaderDataSet;
private System.Data.DataSet QuoteDetailDataSet;
private System.Data.SqlClient.SqlCommand qdCommand;
private System.Data.SqlClient.SqlCommand qhCommand;
private System.Data.SqlClient.SqlDataAdapter DataAdapter;
/* Define connection string */
string connectionString = "Data Source=VISTAPOWMATRICH;Initial Catalog=POWMATQP;User Id=sa;Password=223;Connection Timeout=10";
public ViewQuote()
{
InitializeComponent();
/* Populate text field with sales order number */
txtSOPNUMBE.Text = sopEntryWindow.SopNumber.Value;
/* Define the dataset for the Quote Header Information */
qhConnection = new System.Data.SqlClient.SqlConnection(connectionString);
qhConnection.Open();
QuoteHeaderDataSet = new System.Data.DataSet();
QuoteHeaderDataSet.CaseSensitive = false;
qhCommand = new System.Data.SqlClient.SqlCommand();
qhCommand.Connection = qhConnection;
qhCommand.CommandText = "select top 1 QUOTE_NUMBER_OEQH,SEQUENCE_NUMBER_OEQH,REVALIDATE_NUMB_OEQH,CUSTOMER_NUMBER_OEQH,SALES_AGENT_OEQH,DATE_OF_QUOTE_OEQH,CUSTOMER_NAME_OEQH,CUSTOMR_CONTACT_OEQH,CUSTOMER_PO_#_OEQH,AMRKCODE_OEQH from SOPLINES s1, CSTQUTHD s2 where s1.QUOTE_NUMBER_SOPL=s2.QUOTE_NUMBER_OEQH and s1.SEQUENCE_NUMBER_SOPL=s2.SEQUENCE_NUMBER_OEQH and s1.REVALIDATE_NUMBER_SOPL=s2.REVALIDATE_NUMB_OEQH AND s1.sopnumbe_sopl = '" + sopEntryWindow.SopNumber.Value +"'";
DataAdapter = new System.Data.SqlClient.SqlDataAdapter();
DataAdapter.SelectCommand = qhCommand;
DataAdapter.TableMappings.Add("Table", "QuoteHeader");
DataAdapter.Fill(QuoteHeaderDataSet);
this.txtQuoteNumber.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "QUOTE_NUMBER_OEQH");
this.txtSequenceNumber.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "SEQUENCE_NUMBER_OEQH");
this.txtRevalidateNumber.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "REVALIDATE_NUMB_OEQH");
this.txtCustomerNumber.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "CUSTOMER_NUMBER_OEQH");
this.txtSalesAgent.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "SALES_AGENT_OEQH");
this.txtDateOfQuote.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "DATE_OF_QUOTE_OEQH");
if (txtDateOfQuote.Text != "" )
{
txtDateOfQuote.Text = Convert.ToDateTime(txtDateOfQuote.Text).ToString("MM/dd/yy");
}
this.txtCustomerName.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "CUSTOMER_NAME_OEQH");
this.txtCustomerContact.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "CUSTOMR_CONTACT_OEQH");
this.txtCustRefNumber.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "CUSTOMER_PO_#_OEQH");
this.txtMarket.DataBindings.Add("Text", QuoteHeaderDataSet.Tables["QuoteHeader"], "AMRKCODE_OEQH");
/* Make sure a quote was found for this sales order */
/* Define the dataset for the Quote Detail Information */
qdConnection = new System.Data.SqlClient.SqlConnection(connectionString);
qdConnection.Open();
QuoteDetailDataSet = new System.Data.DataSet();
QuoteDetailDataSet.CaseSensitive = false;
qdCommand = new System.Data.SqlClient.SqlCommand();
qdCommand.Connection = qdConnection;
qdCommand.CommandText = "SELECT LINE_NUMBER_OEQL,PART_NUMBER_OEQL,QUOTE_QUANTITY_OEQL,PART_DESCRPTION_OEQL,UNIT_OF_MEASURE_OEQL,VENDOR_QUOT_CST_OEQL,VENDOR_QUOT_QTY_OEQL,VENDOR_QT_DATE_OEQL,VENDOR_#_QUOTE_OEQL,QUOTE_SELL_PRIC_OEQL,DELIVERY_TEXT_OEQL,QT_LINE_COMMENT_OEQL from SOPLINES s1, CSTQUTLN s2 where s1.QUOTE_NUMBER_SOPL=s2.QUOTE_NUMBER_OEQL and s1.SEQUENCE_NUMBER_SOPL=s2.SEQUENCE_NUMBER_OEQL and s1.REVALIDATE_NUMBER_SOPL=s2.REVALIDATE_NUMB_OEQL AND S1.LINE_NUMBER_SOPL=S2.LINE_NUMBER_OEQL AND s1.sopnumbe_sopl = '" + sopEntryWindow.SopNumber.Value + "' ORDER BY S2.LINE_NUMBER_OEQL";
DataAdapter = new System.Data.SqlClient.SqlDataAdapter();
DataAdapter.SelectCommand = qdCommand;
DataAdapter.TableMappings.Add("Table", "QuoteDetail");
DataAdapter.Fill(QuoteDetailDataSet);
datagridQuoteDetail.ReadOnly = true;
datagridQuoteDetail.RowHeadersVisible = false;
datagridQuoteDetail.DataSource = QuoteDetailDataSet.Tables["QuoteDetail"].DefaultView;
datagridQuoteDetail.Columns[0].Width = 40;
datagridQuoteDetail.Columns[0].DefaultCellStyle.Format = "N2";
datagridQuoteDetail.Columns[0].HeaderText = "Line";
datagridQuoteDetail.Columns[1].Width = 110;
datagridQuoteDetail.Columns[1].HeaderText = "Part Number";
datagridQuoteDetail.Columns[2].Width = 40;
datagridQuoteDetail.Columns[2].HeaderText = "QTY";
datagridQuoteDetail.Columns[3].Width = 200;
datagridQuoteDetail.Columns[3].HeaderText = "Part Description";
datagridQuoteDetail.Columns[4].Width = 40;
datagridQuoteDetail.Columns[4].HeaderText = "U/M";
datagridQuoteDetail.Columns[5].Width = 60;
datagridQuoteDetail.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
datagridQuoteDetail.Columns[5].DefaultCellStyle.Format = "c";
datagridQuoteDetail.Columns[5].HeaderText = "Vendor Cost";
datagridQuoteDetail.Columns[6].Width = 50;
datagridQuoteDetail.Columns[6].HeaderText = "Vendor Quantity";
datagridQuoteDetail.Columns[7].Width = 60;
datagridQuoteDetail.Columns[7].HeaderText = "Quote Date";
datagridQuoteDetail.Columns[8].Width = 60;
datagridQuoteDetail.Columns[8].HeaderText = "Vendor Number";
datagridQuoteDetail.Columns[9].Width = 60;
datagridQuoteDetail.Columns[9].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
datagridQuoteDetail.Columns[9].DefaultCellStyle.Format = "c";
datagridQuoteDetail.Columns[9].HeaderText = "Sell Price";
datagridQuoteDetail.Columns[10].Width = 100;
datagridQuoteDetail.Columns[10].HeaderText = "Delivery";
datagridQuoteDetail.Columns[11].Width = 400;
datagridQuoteDetail.Columns[11].HeaderText = "Comment";
/* Close the detail connection */
try
{
qdConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
/* Close the header connection */
try
{
qhConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Hide();
this.Dispose();
}
private void txtSOPNUMBE_TextChanged(object sender, EventArgs e)
{
}
private void txtMarket_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.