0

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.

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by prashantpani
0

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.

Edited by sudharani: n/a

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.