Solved

Error converting data type nvarchar to datetime?

Posted on 2014-07-28
3
2,279 Views
Last Modified: 2014-07-29
I'm getting the error "Error converting data type nvarchar to datetime" on the following line:

            cmd.Parameters.AddWithValue("@startTime", row("startTime")).Value = If(row("startTime").ToString.Length = 0, DBNull.Value, row("startTime"))

Open in new window


In the Database table this column ("startTime") is defined as a DateTime data type. Is there a better way to code this line?

Thanks!
0
Comment
Question by:BlakeMcKenna
3 Comments
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 40225804
That line looks fine..

However, in your update or insert statement.. try the following...

StartTime=Convert(datetime,@startTime)
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40225904
Look at the way you DataTable is built and the type of row("startTime")).Value in the debugger. If the "StartTime" field is a datetime field from the start, then something is wrong if row("startTime")).Value is a String, which is what the error message seems to imply.

The problem could also come from the fact that you are sending row("startTime") as the value of the parameter. This is an Object, the system converts it as it sees fit, and it might decide to convert it to a String. You might be better of forcing a date:

CDate(row("startTime")))
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40226622
James,

I tried your solution and that worked!

Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question