1
"en-US"및 "ar-KW"언어를 사용하는 다중 언어 응용 프로그램이 있습니다. 또한 WinForm을 사용하여 DateTimePicker 컨트롤을 사용하고 있습니다. 사용자가 로그인하면 기본 언어가 "en-US"이면 레코드가 저장되지만 기본 언어가 "ar-KW"이면이 날짜 형식이 데이터베이스에 저장되지 않고 오류가 발생합니다. 왜?Culture가 "ar-KW"일 때 Windows Form에서 SQL Server로 날짜를 저장하는 방법
SQL Server의 Employee DateOfBirth 필드의 데이터 형식은 smallDateTime
입니다. VB에서 다음 코드를 사용하여 레코드를 저장하고 있습니다. 백엔드에는 정상적인 INSERT
저장 프로 시저가 있습니다.
Dim oDate As String = Me.dtDateOfBirth.Text
Dim dt As Date
dt = (CType(oDate, Date))
이 왜 오히려 DateTime
유형의 .Text
속성을 변환보다, DateTimePicker
제어 .Value
재산을 사용하지 않습니다
If Me.dtDateOfBirth.Checked = False Then
cmd.Parameters.Add("@DateOfBirth", SqlDbType.SmallDateTime).Value = SqlDateTime.Null
Else
If mUserDefaultLanguage = "ar-KW" Then
Me.dtDateOfBirth.Format = DateTimePickerFormat.Custom
Me.dtDateOfBirth.CustomFormat = "dd/MM/yyyy"
Dim oDate As String = Me.dtDateOfBirth.Text
Dim dt As Date
dt = (CType(oDate, Date))
cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value = SqlDateTime.Parse(dt)
Else
cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value = SqlDateTime.Parse(Me.dtDateOfBirth.Text)
End If
End If
어떤 오류가 발생합니까? –
오류 번호 : 5 System.Data.SqlClient.SqlException : System.Data.SqlClient.SqlConnection.OnError (SqlException 예외, Boolean breadkConnection) .................... .................................................. ......................................... System.Data.SqlClient.SqlComman.InternalExecuteNonQuery (dbAsync 결과 결과, STring methodName, 부울 senToPipe) System.Data.SqlClient.SqlComman.ExecuteNonQuery() – Malik
좋은 물건은 SqlException의'.Errors' 속성에 있습니다. 캡쳐 - 문제가 명확해질 것입니다. –