Error converting data type nvarchar to date in ASP.Net

Last Reply on Nov 22, 2016 07:05 AM By dharmendr

Posted on Nov 21, 2016 10:47 AM

Sir i am getting "Error converting data type nvarchar to date."

i am using sql server 2008 r2 

and my field  datatype is date

 i want to store current date (only) dd-mm-yyyy formate

 Dim pdate As String = DateTime.Parse(DateTime.Now.ToString()).ToShortDateString()
            Dim mfd As String = DateTime.Parse(DateTime.Now.ToString()).ToShortDateString()

and i am inserting it to sql table

 

please help me

Posted on Nov 21, 2016 10:57 AM

or should i change data type date to datetime


Posted on Nov 22, 2016 07:05 AM

Hi yogeshc,

If you want to store the date in dd-mm-yyyy format then you have to change the datatype to VARCHAR(10). Else in database it will saved as like '2016-11-22'. What you can do is save the data with datatype date. But when retrive from database change the format as per your requirement in code.