SQL Server データベースにデータ型の列があり、date
これを挿入します1999-12-23
。データベースで選択クエリを実行すると1999-12-23
日付が表示されますが、データベースを c# winform アプリケーションに接続し、表示される日付を取得すると1999-12-23 00:00:00
(つまり、日付と時刻が表示されます)。
これらは私が使用したコードです
テーブルの作成
CREATE TABLE Users.Personal
(
/*...Other Codes for the table this is the main problem*/
DateofReg date NOT NULL
)
クエリを選択
SELECT * FROM Users.Personal
(これにより、日付が として表示されます1999-12-23
)
データベースへの接続
private void RetrievePersonalDetails()
{
SqlConnection myConnection = new SqlConnection("server=AMESINLOLA;" +
"Trusted_Connection=yes;" +
"database=Crm_Db;");
myConnection.Open();
SqlCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "SELECT * FROM Users.Personal WHERE UniqueID='" + uniqueid + "'";
myCommand.CommandType = CommandType.Text;
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
//Other codes inserting to textbox but this is the main problem
txtDor.Text = myReader["DateofReg"].ToString();
}
else
{
MessageBox.Show("Empty");
}
myConnection.Close();
myReader.Close();
}
(これにより、日付が として表示されます1999-12-23 00:00:00
)
アプリケーションでは日付が時間とともに表示されるのに、データベースではうまく表示されるのはなぜですか? また、日付のみを表示するにはどうすればよいですか?