[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DATETIME <NULL>

Posted on 2004-10-25
4
Medium Priority
?
508 Views
Last Modified: 2012-06-27
Hi,
Visual Basic 2003 Web App. This code fires from select column on datagrid. When fired the row from datagrid is copied to sql 2000 table. Everything was working until the field was left null. It's not an option to make the field required forcing the user to enter a date.


SqlConnection1.Open()
Dim rinsertCommand As SqlCommand = New SqlCommand
rinsertCommand.Connection = SqlConnection1
rsql = "insert into reschedulehistory(ReqShipDate)
"values (@ReqShipDate)
rinsertCommand.CommandText = rsql
rinsertCommand.Parameters.Add("@ReqShipDate", System.Data.SqlDbType.DateTime).Value = DateTime.Parse(colreqshipdate)
rinsertCommand.ExecuteNonQuery()
SqlConnection1.Close()

I get this error: The string was not recognized as a valid DateTime. There is a unknown word starting at index 1

I can paste all the code if you like.
Thanks,
Donnie

0
Comment
Question by:Donnie4572
[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
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12406326
Why don't try with this:

If Not typeof(colreqshipdate) is DBNull Then
    rinsertCommand.Parameters.Add("@ReqShipDate", System.Data.SqlDbType.DateTime).Value = DateTime.Parse(colreqshipdate)
Else
   rinsertCommand.Parameters.Add("@ReqShipDate", System.Data.SqlDbType.DateTime).Value = DBNull.Value
End If
0
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 2000 total points
ID: 12406346
If the compiler say you that colreqshipdate isn't a type then you can try with this:

dim obj as Object
obj = colreqshipdate
If Not typeof(obj) is DBNull Then
    rinsertCommand.Parameters.Add("@ReqShipDate", System.Data.SqlDbType.DateTime).Value = DateTime.Parse(colreqshipdate)
Else
   rinsertCommand.Parameters.Add("@ReqShipDate", System.Data.SqlDbType.DateTime).Value = DBNull.Value
End If
0
 
LVL 12

Author Comment

by:Donnie4572
ID: 12406872
Thanks for reply.

Sorry,
I can't get either of these to work. I get error:  String or binary data would be truncated. The statement has been terminated.

Any Ideas?
Thanks for your help.
0
 
LVL 12

Author Comment

by:Donnie4572
ID: 12407010
Your right. The second answer works! I had a second datetime/<NULL> field that that generated this error: String or binary data would be truncated. The statement has been terminated.
Thank You.
Donnie
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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