?
Solved

DATETIME <NULL>

Posted on 2004-10-25
4
Medium Priority
?
509 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
  • 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

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

601 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