Monday, March 19, 2012

Date Insertion problem

I am using BLL for inserting my data. I have some date filed and I have declare that field in BLL as date only. But still it is giving me error string in wrong format. My database is in SQL Server2005

can u give me a code, how you are declared date in BLL and how you are assining the values to that date variable in BLL, it may be your date variable string is not in proper format.

|||

================================Codes in BLL =============================================================================

<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert,True)> _

PublicFunction AddTempEmployee(ByVal DDKSFileNoAsString,ByVal firstNameAsString,ByVal middleNameAsString,ByVal lastNameAsString, _

ByVal dateOfBirthAsDate,ByVal maritualStatusAsInteger,ByVal nationalityAsString,ByVal passportNumberAsString, _

ByVal passportIssuePlaceAsString,ByVal passportIssueDateAsDate,ByVal passportExpiryDateAsDate,ByVal civilIDNumberAsString, _

ByVal civilIDExpiryDateAsDate,ByVal residenceNumberAsString,ByVal homePhoneNumberAsString, _

ByVal alternatePhoneNumberAsString,ByVal kuwaitHomeAddressAsString)AsBoolean

Dim tempEmployeesAsNew DDKS.TempEmployeeDataTableDim tempEmployeeAs DDKS.TempEmployeeRow = tempEmployees.NewTempEmployeeRow

tempEmployee.DDKSFileNo = DDKSFileNo

tempEmployee.FirstName = firstName

tempEmployee.MiddleName = middleName

tempEmployee.LastName = lastName

tempEmployee.DateOfBirth = dateOfBirth

tempEmployee.MaritualStatus = maritualStatus

tempEmployee.Nationality = nationality

tempEmployee.PassportNumber = passportNumber

tempEmployee.PassportIssueDate = passportIssueDate

tempEmployee.PassportExpiryDate = passportExpiryDate

tempEmployee.CivilIDNumber = civilIDNumber

tempEmployee.CivilIDExpiryDate = civilIDExpiryDate

tempEmployee.ResidenceNumber = residenceNumber

tempEmployee.HomePhoneNumber = homePhoneNumber

tempEmployee.AlternatePhoneNumber = alternatePhoneNumber

tempEmployee.KuwaitHomeAddress = kuwaitHomeAddress

tempEmployees.AddTempEmployeeRow(tempEmployee)

Dim rowAffectedAsInteger = Adapter.Update(tempEmployees)

Return 1

EndFunction

========================================= Ends here ===============================================================================

===============================Codes in aspx file==========================================================================================================

<tdstyle="width:150px; height: 27px;"><cc1:MaskedTextBoxID="txDateOfBirth"runat="server"Text='<%# Bind("DateOfBirth", "{0:d}") %>'Mask="99-99-9999"ReadOnly="True"></cc1:MaskedTextBox>

=====================================ends here=====================================================================================================

|||

chk whether you are passing correct values to correct varibale,,

this is not a solution, but sometime we do small mistakes,

chk whether ur passing string to string variables, date to date varibles and integer to integer, and also chk the ur datatypes of the columns for those fields.

DDKsFileNo String
Firstname String
MiddleName String
LastName String
DateofBirth Date
MaritualStatus Integer (I think this is Boolen or bit)
nationality String
PassportNumber String
PassportIssuePlace String
PassportIssueDate Date
PassportExpiryDate Date
CivilIDnumber string
CivilIDExpiryDate Date
residenceNumber String
HomePhoneNumber String
alternatePhoneNumber string
kuwaitHomeAddress string

|||

chk whether you are passing correct values to correct varibale,,

this is not a solution, but sometime we do small mistakes,

chk whether ur passing string to string variables, date to date varibles and integer to integer, and also chk the ur datatypes of the columns for those fields.

DDKsFileNo String
Firstname String
MiddleName String
LastName String
DateofBirth Date
MaritualStatus Integer
nationality String
PassportNumber String
PassportIssuePlace String
PassportIssueDate Date
PassportExpiryDate Date
CivilIDnumber string
CivilIDExpiryDate Date
residenceNumber String
HomePhoneNumber String
alternatePhoneNumber string
kuwaitHomeAddress string

|||

chk whether you are passing correct values to correct varibale,,

this is not a solution, but sometime we do small mistakes,

chk whether ur passing string to string variables, date to date varibles and integer to integer, and also chk the ur datatypes of the columns for those fields.

DDKsFileNo String
Firstname String
MiddleName String
LastName String
DateofBirth Date
MaritualStatus Integer
nationality String
PassportNumber String
PassportIssuePlace String
PassportIssueDate Date
PassportExpiryDate Date
CivilIDnumber string
CivilIDExpiryDate Date
residenceNumber String
HomePhoneNumber String
alternatePhoneNumber string
kuwaitHomeAddress string

|||

My problem got caught it something like i was using "-" as seprator in application and my regional setting was using "/" so i change same in my application and start working.

Thanx for help

No comments:

Post a Comment