|
-
Jun 16th, 2010, 10:07 AM
#1
Thread Starter
Addicted Member
[RESOLVED] DateTime DataColumn
I'm adding a DateTime DataColumn to a DataTable like this:
Code:
Dim colDate As DataColumn = New DataColumn("Date")
colDate.DataType = System.Type.GetType("System.DateTime")
dt.Columns.Add(colDate)
Then when I try to add it to my datatable, if the value is Nothing I get an error saying string was not recognized as a valid DateTime. I'm having trouble getting this to work. What would you do?
Thanks
-
Jun 16th, 2010, 10:19 AM
#2
Thread Starter
Addicted Member
Re: DateTime DataColumn
Actually it was pretty easy. If there's an empty string, just set it to Nothing:
If (LineItems(3).ToString().Length = 0) Then
LineItems(3) = Nothing
End If
-
Jun 16th, 2010, 10:26 AM
#3
Re: [RESOLVED] DateTime DataColumn
First up, do it the easy way:
vb.net Code:
dt.Columns.Add("Date", GetType(Date))
As for this error you mention, if it's telling you anything to do with Strings then you're doing it wrong because you should only be putting Date values or DBNull.Value into a Date column. Strings should never come into play at all. You're going to have to show us how you're putting the data into the column so that we can see exactly what you're doing wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|