I have a database with a table PhoneHistory
and a column Date
, which of datetime
datatype.
I tried using this answer but I couldn't get it to work. Because I need a DataTable
as the return type and I'm also currently using a DataAdapter
.
This is what I currently have. I only get the date with hours and the minutes but not the seconds and milliseconds.
public static DataTable GetHistory()
{
string query = "SELECT TOP 100 Date FROM PhoneHistory";
return SelectSql(connectionString, query, "");
}
private static DataTable SelectSql(string connectionString, string query, string dtName, params object[] args)
{
using (OleDbConnection con = new OleDbConnection(connectionString))
{
try
{
con.Open();
}
catch (Exception ex)
{
Global.Log($"Es konnte keine Verbindung zur Datenbank hergestellt werden! Fehlermeldung: [{ex.Message}]");
return new DataTable(dtName);
}
using (OleDbCommand command = new OleDbCommand(query, con))
{
for (int i = 0; i < args.Length; i++)
{
command.Parameters.AddWithValue($"@p{i + 1}", args[i]);
}
using (OleDbDataAdapter a = new OleDbDataAdapter(command))
{
DataTable dt = new DataTable(dtName);
try
{
a.Fill(dt);
return dt;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
return new DataTable(dtName);
}
}
}
}
I need to use a DataTable
as the return type.
I want to get the dates like this (this is how it looks inside the database):
2019-07-30 10:10:16.526
2019-07-30 10:08:58.711
but I always get the dates like this (this is what I get with the code):
2019-07-30 10:10:00.000
2019-07-30 10:08:00.000