SQL Server 2008 데이터베이스에서 문자열로 저장된 날짜를 smalldatetime
으로 변환하려고합니다.SQL Server 2008에서 값을 문자열에서 날짜 형식으로 변환
저장된 문자열의 형식은 16/12/2007
내가 제거 /과로 교체 할 - 내가 생각 다음과 같은 오류
Conversion from string "16/12/2007" to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from string "16/12/2007" to type 'Date' is not valid.
Source Error:
Line 34: NewsItem.Visible = True
Line 35: NewsItem.Date_Modified = CDate(GetContent.Ndate)
Line 36: NewsItem.Date_Published = CDate(GetContent.Ndate)
을 받고 16-12-2007
입니다 적절한 날짜 형식을 얻기 위해 /
문자를 -
으로 대체하는 함수를 작성한 다음 데이터베이스를 업데이트하지만 시간이 오래 걸립니다.
날짜를 문자열로 저장하지 않으려면 문제가 발생하지 않아야합니다. SQL Server는 완벽하게 사용할 수있는'date' 및'datetime2' 데이터 형식을 가지고 있습니다. ADO.NET은 .NET DateTime 형식과의 변환 방법을 알고 있습니다. 이 설정을 벗어나 부적절한 저장 유형을 사용하는 경우에만 서식 문제가 발생합니다. –