Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error converting data type nvarchar to datetime?

Posted on 2014-07-28
3
Medium Priority
?
2,456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

705 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