I'm relatively new to C#, SQL Server, and Stackoverflow.
I want the format of my date to stay the same from SQL Server to my C# code. I have a screenshot of the SQL Server table:
.
I just want the format to stay the same. I want the format to stay yyyy-mm-dd instead when I retrieve the data the format is dd/mm/yyyy 0:00:00.
I then use the following code to retrieve the data from the server:
ArrayList a = new ArrayList();
DataTable d = new DataTable();
string sql = "SELECT * FROM myServer";
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, conn);
MySqlDataAdapter myA = new MySqlDataAdapter(cmd);
myA.Fill(d);
cmd.ExecuteNonQuery();
foreach (DataRow row in d.Rows)
{
FitnessManager f = new FitnessManager();
f.testDate = row["testDate"].ToString();
f.tDate = row["tDate"].ToString();
f.dtDate = row["dtDate"].ToString();
a.Add(f);
}
return a;
I would expect the results in the ArrayList to be 2020-10-13, instead I'm getting 10/11/2020 0:00:00.
I do not know why this happens for how to fix this.
DATEin SQL and aDateTimein .NET are binary objects. What you see in both cases is two different representations of the same (or maybe translated, but similar) binary data. In both systems there are many options to control the translation from binary data to strings.datetime,smalldatetime, etc). Please improve this post so we can help you.ArrayListcmd.ExecuteNonQuery();? It useless in your code.