This is what the database data looks like in SQL Server Management Studio:
Here it is in design view:
This is what the datagrid looks like:
This is the code that I am using to import the data from SQL Server into the datagrid.
SqlConnection connection = new SqlConnection(@"Data Source=.;Initial Catalog=TheatreDatabase2.0;Integrated Security=True");
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM performanceTable", connection);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable data = new DataTable();
da.Fill(data);
dgdPerformance.ItemsSource = data.DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
I am wondering why there is the "12:00:00 AM" at the end of each date in the datagrid and how I would go about removing it.
It uses default DateTime
representation, which in your system, comes from your thread current culture.
If you want to change it, you should derive your columns manually (use DataGridTemplateColumn, and use this in your CellTemplate
):
<Textbox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" />