Solved

Error converting data type nvarchar to datetime?

Posted on 2014-07-28
3
2,146 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 M
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now