R
RSH
I am having a bit of trouble filling a datatable with a query. I'm getting
the error message:
System.FormatException: String was not recognized as a valid DateTime. at
System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles
styles) at System.DateTime.Parse(String s, IFormatProvider provider,
DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider
provider) at System.Convert.ToDateTime(String value, IFormatProvider
provider) at System.String.System.IConvertible.ToDateTime(IFormatProvider
provider) at System.Convert.ToDateTime(Object value) at
System.Data.Common.DateTimeStorage.Set(Int32 record, Object value) at
System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <>
in InstallationDate Column. Expected type is DateTime.
The problem is that the tables are arrived at dynamically and the code
cycles through the tables one by one and outputs the datatables at the end
of each. How can I have it ignore the offending information dynamically
before causing the error. If the tables were known in advance I could write
a where clause but since it is all dynamica I dont have the information to
create a where clause.
Any ideas?
Thanks,
RSH
Private Sub ShowAccessTableStructure()
Dim objDS As DataSet = New DataSet
Dim objDT1 As DataTable
Dim strDisplay As String
Dim i As Integer
Dim strTablename As String
Dim dc As DataColumn
Dim cn As String
Dim cdt As String
Dim objConn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Intranet\Data\Intranet.mdb")
Dim objConn2 As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Intranet\Data\Intranet.mdb")
objConn.Open()
objConn2.Open()
objDT1 =
objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New
Object() {Nothing, Nothing, Nothing, Nothing})
For i = 0 To objDT1.Rows.Count - 1
DisplayArea.Text += "<table border=0 cellpadding=0 cellspacing=0><tr><td
bgcolor='#000000'><table border=0 cellpadding=3 cellspacing=1>"
strTablename = objDT1.Rows(i).Item(2)
DisplayArea.Text += "<tr bgcolor='#ddeeaa'><td><b>" & strTablename &
"</b></td></tr>"
Dim objDA2 As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [" &
strTablename & "]", objConn2)
objDA2.Fill(objDS, "DBRows")
For Each dc In objDS.Tables("DBRows").Columns
cn = dc.ColumnName
DisplayArea.Text += "<tr bgcolor='#ffffff'><td>" & cn & "</td></tr>"
Next
DisplayArea.Text += "</table></td></tr></table><br>"
Next
objConn2.Close()
objConn.Close()
End Sub
the error message:
System.FormatException: String was not recognized as a valid DateTime. at
System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles
styles) at System.DateTime.Parse(String s, IFormatProvider provider,
DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider
provider) at System.Convert.ToDateTime(String value, IFormatProvider
provider) at System.String.System.IConvertible.ToDateTime(IFormatProvider
provider) at System.Convert.ToDateTime(Object value) at
System.Data.Common.DateTimeStorage.Set(Int32 record, Object value) at
System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <>
in InstallationDate Column. Expected type is DateTime.
The problem is that the tables are arrived at dynamically and the code
cycles through the tables one by one and outputs the datatables at the end
of each. How can I have it ignore the offending information dynamically
before causing the error. If the tables were known in advance I could write
a where clause but since it is all dynamica I dont have the information to
create a where clause.
Any ideas?
Thanks,
RSH
Private Sub ShowAccessTableStructure()
Dim objDS As DataSet = New DataSet
Dim objDT1 As DataTable
Dim strDisplay As String
Dim i As Integer
Dim strTablename As String
Dim dc As DataColumn
Dim cn As String
Dim cdt As String
Dim objConn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Intranet\Data\Intranet.mdb")
Dim objConn2 As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Intranet\Data\Intranet.mdb")
objConn.Open()
objConn2.Open()
objDT1 =
objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New
Object() {Nothing, Nothing, Nothing, Nothing})
For i = 0 To objDT1.Rows.Count - 1
DisplayArea.Text += "<table border=0 cellpadding=0 cellspacing=0><tr><td
bgcolor='#000000'><table border=0 cellpadding=3 cellspacing=1>"
strTablename = objDT1.Rows(i).Item(2)
DisplayArea.Text += "<tr bgcolor='#ddeeaa'><td><b>" & strTablename &
"</b></td></tr>"
Dim objDA2 As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [" &
strTablename & "]", objConn2)
objDA2.Fill(objDS, "DBRows")
For Each dc In objDS.Tables("DBRows").Columns
cn = dc.ColumnName
DisplayArea.Text += "<tr bgcolor='#ffffff'><td>" & cn & "</td></tr>"
Next
DisplayArea.Text += "</table></td></tr></table><br>"
Next
objConn2.Close()
objConn.Close()
End Sub