Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends, i am facing problem with the following error:
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated." the code as below...

SQL
cmd = New SqlCommand("INSERT INTO [Inq_Details]  ([Region] ,[Inq_No],[Inq_Date],[Lvl]  ,[City] ,[Source_of_Inquiry] ,[Model] ,[Type] ,[Cap_T]" _
                  & ",[Color],[Material] ,[Machines_in_This_Inq] ,[Customer_Name],[New_Repeat] ,[Sales_Turnover] ,[Location]" _
              & ",[Single_Loc_Or_Multiple] ,[Contact_Person] ,[Contact_Person_Phone] ,[Contact_Person_Email] ,[Company_Management]" _
              & ",[Customers_Customer],[Own_Product_Jobwork] ,[Product_To_Moulded]   ,[Application_Segment] ,[App_segment_Ref]" _
              & ",[Customer_Segment] ,[Total_Machines_Installed] ,[Total_Machines_by_WML] ,[Last_purchase_from_WML],[Last_pur_from_others]" _
              & ",[Other_Machines_used] ,[PD_L_mm] ,[PD_B_mm] ,[PD_H_mm] ,[Product_Shot_Weights],[Material_Type],[Material_Grade]" _
             & " ,[Output_Expected] ,[Injection_Pressure_Bar],[MD_L_mm],[MD_B_mm],[MD_H_mm],[Mould_Weight],[Mould_type]" _
              & ",[Ejection_Type] ,[Tonnage_Reqt],[Factory] ,[Factory_Availability_Date],[Space],[Space_Availability_Date]" _
              & ",[Power] ,[Power_Availability_Date]  ,[Mould],[Mould_Availability_Date],[Expected_Delivery_Date],[Machine_Financed]" _
             & " ,[Delivery_Location] ,[Competitors_with_whom_customer_interacting] ,[Inquiry_Evaluation_Date],[Quotation_Submission_Date]" _
              & ",[First_Negotiation_Date],[Second_Negotiation_Date],[Final_Negotiation_Date],[PO_Collection_Date],[Reason]" _
              & ",[Competitor] ,[Price] ,[Specification],[Other_Reason],[Login_ID],[Modify_Date]) VALUES" _
              & " ('" & lblRegion.Text.ToUpper & "'," & lblInqNo.Text & ",'" & Format(CDate(lblDate.Text.Trim), "MM/dd/yyyy") & "','" & lblLevel.Text.ToUpper & "','" & txtCity.Text.ToUpper & "','" & ddlSourceOfInquiry.SelectedItem.Text & "','" & ddlModel.SelectedItem.Text & "','" & ddlType.SelectedItem.Text & "'," & ddlCap.SelectedItem.Text & "," _
             & "'" & ddlColor.SelectedItem.Text & "','" & ddlMaterial.SelectedItem.Text & "'," & txtMCInThisINQ.Text & ",'" & txtCustName.Text.ToUpper.Trim & "','" & ddlNewRepeat.SelectedItem.Text & "'," & txtSalesTurnOver.Text & ",'" & txtLocation.Text.ToUpper & "'," _
             & "'" & ddlSnglMulLoc.SelectedItem.Text & "','" & txtContPRSN.Text.ToUpper.Trim & "'," & txtConPRSNPhone.Text & ",'" & txtConPRSNEmail.Text.ToUpper & "','" & ddlCompMgt.SelectedItem.Text & "'," _
             & "'" & txtCustCust.Text.ToUpper.Trim & "','" & ddlOwnJObWork.SelectedItem.Text & "','" & txtProdToBeMoulded.Text.ToUpper & "','" & ddlAppSegment.SelectedItem.Text & "','" & txtAppSegRefCustDTL.Text.ToUpper & "'," _
             & "'" & ddlCustSegment.SelectedItem.Text & "'," & txtTotMCInstalled.Text & "," & txtTotalMCByWML.Text & "," & txtLastPurFrmWML.Text & "," & txtLastPurFrmOther.Text & " ," _
             & "'" & txtOtherMCUsed.Text.ToUpper & "'," & txtPRDTL.Text & "," & txtPRDTB.Text & "," & txtPRDTH.Text & "," & txtPRDTShotWeight.Text & ",'" & txtPRDTMatType.Text.ToUpper & "','" & txtPRDTMatGrd.Text.ToUpper & "'," _
             & "'" & txtPRDTOPExpected.Text & "'," & txtPRDTInjPressure.Text & "," & txtMOUL.Text & "," & txtMOUB.Text & "," & txtMOUH.Text & "," & txtMOUWeight.Text & ",'" & ddlMOUType.SelectedItem.Text & "', " _
             & "'" & txtMOUEjectionTyep.Text.ToUpper & "'," & txtMOUTonnageREQT.Text & ",'" & ddlFactory.SelectedItem.Text & "','" & Format(txtFacotyADate.Text & "','" & ddlSpace.SelectedItem.Text & "','" & Format(CDate(txtSpaceADate.Text.Trim), "MM/dd/yyyy") & "'," _
             & "'" & ddlPower.SelectedItem.Text & "','" & Format(CDate(txtPowerADate.Text.Trim), "MM/dd/yyyy") & "','" & ddlMouldAvailability.SelectedItem.Text & "','" & Format(CDate(txtMouldADate.Text.Trim), "MM/dd/yyyy") & "','" & Format(CDate(txtORDRExpDelDate.Text.Trim), "MM/dd/yyyy") & "','" & txtORDRMCFinancedSource.Text & "'," _
             & "'" & txtORDRDelLocation.Text.ToUpper.Trim & "','" & txtCustInteracting.Text.ToUpper & "','" & Format(CDate(txtInqEvalDate.Text.Trim), "MM/dd/yyyy") & "', '" & Format(CDate(txtQuotSubDate.Text.Trim), "MM/dd/yyyy") & "'," _
             & "'" & Format(CDate(txtFirstNEgoDate.Text.Trim), "MM/dd/yyyy") & "','" & Format(CDate(txtSecNegoDate.Text.Trim), "MM/dd/yyyy") & "','" & Format(CDate(txtFinalNegoDate.Text.Trim), "MM/dd/yyyy") & "', '" & Format(CDate(txtPOColleDate.Text.Trim), "MM/dd/yyyy") & "','" & ddlReason.SelectedItem.Text & "'," _
             & "'" & txtCompititor.Text & "'," & txtPrice.Text & ",'" & txtSpecification.Text.ToUpper & "','" & txtOtherReason.Text.ToUpper & "','" & Session("UserName").ToString.ToUpper & "','" & Format(CDate(Now), "MM/dd/yyyy") & "')"), con.con)
Posted
Updated 24-Jul-12 1:37am
v2
Comments
_Amy 24-Jul-12 7:31am    
Where is the code? Without viewing how we can find the solution of the error?
Rockstar_ 24-Jul-12 7:33am    
i think u r trying to insert or update the date type with the char type. plz insert or update with the proper data.

Look at the data you are passing in: it contains a date in string format (which is a bad idea to start with) which SQL cannot convert to a valid DateTime value. I would recommend that you convert the string to a DateTime value and pass that to SQL via a parametrised query.
 
Share this answer
 
SQL
cmd = New SqlCommand("INSERT INTO [Inq_Details]  ([Region] ,[Inq_No],[Inq_Date],[Lvl]  ,[City] ,[Source_of_Inquiry] ,[Model] ,[Type] ,[Cap_T]" _
                            & ",[Color],[Material] ,[Machines_in_This_Inq] ,[Customer_Name],[New_Repeat] ,[Sales_Turnover] ,[Location]" _
                        & ",[Single_Loc_Or_Multiple] ,[Contact_Person] ,[Contact_Person_Phone] ,[Contact_Person_Email] ,[Company_Management]" _
                        & ",[Customers_Customer],[Own_Product_Jobwork] ,[Product_To_Moulded]   ,[Application_Segment] ,[App_segment_Ref]" _
                        & ",[Customer_Segment] ,[Total_Machines_Installed] ,[Total_Machines_by_WML] ,[Last_purchase_from_WML],[Last_pur_from_others]" _
                        & ",[Other_Machines_used] ,[PD_L_mm] ,[PD_B_mm] ,[PD_H_mm] ,[Product_Shot_Weights],[Material_Type],[Material_Grade]" _
                       & " ,[Output_Expected] ,[Injection_Pressure_Bar],[MD_L_mm],[MD_B_mm],[MD_H_mm],[Mould_Weight],[Mould_type]" _
                        & ",[Ejection_Type] ,[Tonnage_Reqt],[Factory] ,[Factory_Availability_Date],[Space],[Space_Availability_Date]" _
                        & ",[Power] ,[Power_Availability_Date]  ,[Mould],[Mould_Availability_Date],[Expected_Delivery_Date],[Machine_Financed]" _
                       & " ,[Delivery_Location] ,[Competitors_with_whom_customer_interacting] ,[Inquiry_Evaluation_Date],[Quotation_Submission_Date]" _
                        & ",[First_Negotiation_Date],[Second_Negotiation_Date],[Final_Negotiation_Date],[PO_Collection_Date],[Reason]" _
                        & ",[Competitor] ,[Price] ,[Specification],[Other_Reason],[Login_ID],[Modify_Date]) VALUES" _
                        & " ('" & lblRegion.Text.ToUpper & "'," & lblInqNo.Text & ",'" & Format(CType(lblDate.Text.Trim, Date), "MM/dd/yyyy HH:mm") & "','" & lblLevel.Text.ToUpper & "','" & txtCity.Text.ToUpper & "','" & ddlSourceOfInquiry.SelectedItem.Text & "','" & ddlModel.SelectedItem.Text & "','" & ddlType.SelectedItem.Text & "'," & ddlCap.SelectedItem.Text & "," _
                       & "'" & ddlColor.SelectedItem.Text & "','" & ddlMaterial.SelectedItem.Text & "'," & txtMCInThisINQ.Text & ",'" & txtCustName.Text.ToUpper.Trim & "','" & ddlNewRepeat.SelectedItem.Text & "'," & txtSalesTurnOver.Text & ",'" & txtLocation.Text.ToUpper & "'," _
                       & "'" & ddlSnglMulLoc.SelectedItem.Text & "','" & txtContPRSN.Text.ToUpper.Trim & "'," & txtConPRSNPhone.Text & ",'" & txtConPRSNEmail.Text.ToUpper & "','" & ddlCompMgt.SelectedItem.Text & "'," _
                       & "'" & txtCustCust.Text.ToUpper.Trim & "','" & ddlOwnJObWork.SelectedItem.Text & "','" & txtProdToBeMoulded.Text.ToUpper & "','" & ddlAppSegment.SelectedItem.Text & "','" & txtAppSegRefCustDTL.Text.ToUpper & "'," _
                       & "'" & ddlCustSegment.SelectedItem.Text & "'," & txtTotMCInstalled.Text & "," & txtTotalMCByWML.Text & "," & txtLastPurFrmWML.Text & "," & txtLastPurFrmOther.Text & " ," _
                       & "'" & txtOtherMCUsed.Text.ToUpper & "'," & txtPRDTL.Text & "," & txtPRDTB.Text & "," & txtPRDTH.Text & "," & txtPRDTShotWeight.Text & ",'" & txtPRDTMatType.Text.ToUpper & "','" & txtPRDTMatGrd.Text.ToUpper & "'," _
                       & "'" & txtPRDTOPExpected.Text & "'," & txtPRDTInjPressure.Text & "," & txtMOUL.Text & "," & txtMOUB.Text & "," & txtMOUH.Text & "," & txtMOUWeight.Text & ",'" & ddlMOUType.SelectedItem.Text & "', " _
                       & "'" & txtMOUEjectionTyep.Text.ToUpper & "'," & txtMOUTonnageREQT.Text & ",'" & ddlFactory.SelectedItem.Text & "'," & STR1 & ",'" & ddlSpace.SelectedItem.Text & "'," & str2 & "," _
                       & "'" & ddlPower.SelectedItem.Text & "'," & STR3 & ",'" & ddlMouldAvailability.SelectedItem.Text & "'," & STR4 & "," & STR5 & ",'" & txtORDRMCFinancedSource.Text & "'," _
                       & "'" & txtORDRDelLocation.Text.ToUpper.Trim & "','" & txtCustInteracting.Text.ToUpper & "'," & STR6 & ", " & STR10 & "," _
                       & "" & STR7 & "," & STR8 & "," & STR9 & "," & STR & ",'" & ddlReason.SelectedItem.Text & "'," _
                       & "'" & txtCompititor.Text & "'," & txtPrice.Text & ",'" & txtSpecification.Text.ToUpper & "','" & txtOtherReason.Text.ToUpper & "','" & Session("UserName").ToString.ToUpper & "','" & Format(CType(Now, Date), "MM/dd/yyyy HH:mm") & "')", con.con)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900