Hi all,

I have a Subscription database running and i am trying to insert values into it from an ASP web form when i click on a button with an id of 'confirm'. The name of the field is 'startdate' (date data type) and i need to enter today's date into that record but everytime i do it comes with an error message:

"Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string."

The name of the table is 'Subscription' and I am using Visual Basic as my programming language.

Any help would be much appreciated.

Recommended Answers

All 4 Replies

Hi,
Declare the type of Data field as Nchar(10),if U use sql server database.

try this code

Dim con as new sqlconnection
Dim com as new sqlcommand
con.ConnectionString="give connection string"
con.open
com.connection=con
com.commandText="insert into tablename values(@joindate,@...)"
com.parameters.Add("@joindate",Sqldbtype.nchar,10).value=System.DateTime.Today.ToString() 
com.ExcuteNonQuery

Hope this helps U
If it helps make it as solved
Thanks
regards.

I believe your column datatype in the SQL Database in an "DateTime", correct? If so then use sudharani's code except change the SqlDbType over to a DateTime instead of nchar.

Thanks all. I just did the lazy way and changed my data type to nvarchar. This fixed it all up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.