데이터 형식이 "yyyy-MM-dd"인 SQL Server 2008의 데이터 형식이 DATE
인데 C#을 통해 데이터베이스에서 날짜를 선택하고 문자열로 변환하면 시간 부분도 같이 표시됩니다 .SQL Server 2008 Returing Time의 DATE 데이터 유형!
"2012-04-21 12:00:00"
여기에 데이터베이스에 시간을 저장하지 않은 것은 무엇입니까?
string sql = @"select card_no, amount, csc,expdate " +
"from user_account_card " +
"where user_id = '" + loginsession.Auser + "';";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader red = cmd.ExecuteReader();
while (red.Read())
{
loginsession.Cardno = Convert.ToString(red["card_no"]);
loginsession.Cardamount = Convert.ToString(red["amount"]);
loginsession.Csc=Convert.ToString(red["csc"]);
loginsession.Expdate = Convert.ToString(red["expdate"]);//date part
break;
}
MessageBox.Show("database value from database--" +loginsession.Expdate);
시간이 시간없이 저장하는 모든 의도와 목적을 위해 다음 자정으로 표시되는 경우
.NET에서 오히려 문제 (http://en.wiktionary.org/wiki/for_all_intents_and_purposes) –
-
그래서 정말 여기에 SQL 서버의 문제가 아니다 @ 마틴 - 젠장, 내 영어 교정 중이야? 그렇게 어려운 대상이있는 것처럼 보입니다. (팁 주셔서 감사합니다) : D – Hogan
((DateTime) red [ "expdate"]이어야합니다.) ToShortDateString(); – Magnus