problem with datetimepiker

Dear every one Regards

am new in vb.net 

my problem is this!

i developed a windows form if i click on datetimepiker and then select a date then ok

if i do not click any date then massage show

Additional information: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

i have field name with opdate and its data type is also datetime

please help me

thank 

March 23rd, 2015 11:26am

This question is related to windows form, you wont find good solution here  on this forum. Its does not seems directly related to SQL S
Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 1:27pm

Do you have the database field in SQL defined as a DataTime or a VarChar?  Open SQL Server Management Studio and verify the field.  Also make sure you are using the "Value" property of the DataTime picker and not the text.  You should be using DateTime in the SQL database and the VBnet application.

What object are you using in the form to display the data?  Can you post the line where the failure is occurring?

March 23rd, 2015 1:28pm

Good day ABDULLAHAAJSOFT

I assume that in the database you are using datetime data type for the column, but in the application you are using  String type (String class). therefore when moving the data from the app to the database, the SQL Server Engine try to do implicit convert (implicit convert is when you do not use explicate CONVERT or CAST function, and the server find that there is an option to convert the data).

Now the implicit convert did not work since the server found that the string is out-of-range value for a date, and that might be related to the date format.

for example  this implicit convert will work ok:

declare @D datetime = '2015-10-22'

but if you try to use a different format for the date like yyyy-dd-mm then the convert will fail, and you will get the same error as you did. The server tried to convert the number 22 to month but this is out-of-range value for month:

declare @D datetime = '2015-22-10'

What is the solution?

1. dont ever use implicate convert!
Convert the data to the right type before you try to insert it to the database (in the application level)

2. You should not use string in the app as well, but DateTime type for example.

3. If you ahve to convert from string to database datetime then make sure that you use format like yyyy-mm-dd or use the right convert hint as you can see in this link:
http://www.sqlusa.com/bestpractices/datetimeconversion/

Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 1:51pm

Thanks Ronen Ariely

You are absolutely right am using format dd/mm/yyyy

and my table column is as is it possible to insert data as dd/mm/yyyy

how 

thanks once again

March 24th, 2015 3:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics