I'm calling a SQL select statement and displaying the results in a Data Grid. All is working fine EXCEPT that in SQL the order_date column displays as '2004-01-30 09:35:52.000' while the column in my DataGrid displays as '1/30/2004 9:35 AM'. The main problem is that I'm losing the 'seconds' (52 in this example).. I need the seconds value. As a secondary issue, I'd like to know how this works so I can format how the date/time displays in my DataGrid.
The full extent of the little C# program I'm testing with is below. Pretty simple.. and I don't think I'm explicitly defining the date/time format in any way..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test_to_Get_Seconds_From_SQL
{
public partial class Form1 : Form
{
SqlConnection m_cnSQLConnection;
SqlDataAdapter m_daDataAdapter;
DataTable m_dtOrders;
SqlCommand m_comSQLCommand;
public Form1()
{
InitializeComponent();
}
private void btnShowOrders_Click(object sender, EventArgs e)
{
// Set Connection string
string strSQLConnection;
strSQLConnection = @"Initial Catalog=Sandbox;Data Source=WFDW3B79\SQLEXPRESS;Persist Security Info=True;Integrated Security=True;";
// Open connection
using (m_cnSQLConnection = new SqlConnection(strSQLConnection))
{
m_cnSQLConnection.Open();
// Create new DataAdapter
using (m_daDataAdapter = new SqlDataAdapter("SELECT * FROM Orders", m_cnSQLConnection))
{
// Use DataAdapter to fill DataTable
m_dtOrders = new DataTable();
m_daDataAdapter.Fill(m_dtOrders);
// Render data onto the screen
dataGridView.DataSource = m_dtOrders;
}
}
}
}
}