G
Guest
So what I'm trying to do is Create the table tblToLoad which i have done,
then use fill schema to create the proper columns based on strLoadTable
(which is a table name that is passed in via command line ) Then later in my
program insert a datarow into the table. However I receive an error on a
datetime column of the data. I can insert the same row of data by
dynamically creating an insert statement and it will insert without errors
however when I use the LoadDataRow procedure I get the error
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: 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 <20060209> in contactdate Column. Expected type is DateTime.
If i change the value 20060209 to something like 2006-02-09 12:35:29.998 it
inserts fine, however when i use an insert statement the data 20060209
inserts just fine. Why?
Here's a snippet of my program:
string strTableToLoad = "SELECT * FROM " + strLoadTable ;
SqlCommand cmdTableToLoad = new SqlCommand (strTableToLoad,DWConnection);
DataTable tblToLoad = new DataTable(strLoadTable);
SqlCommand cmdTableToLoad = new SqlCommand (strTableToLoad,DWConnection);
da.SelectCommand = cmdTableToLoad;
da.FillSchema(dsInfo, SchemaType.Source, strLoadTable);
da.Fill(dsInfo);
Console.WriteLine("Columns: " + tblToLoad.Columns.Count);
dsInfo.Tables[strLoadTable].LoadDataRow(strTokens,false);
then use fill schema to create the proper columns based on strLoadTable
(which is a table name that is passed in via command line ) Then later in my
program insert a datarow into the table. However I receive an error on a
datetime column of the data. I can insert the same row of data by
dynamically creating an insert statement and it will insert without errors
however when I use the LoadDataRow procedure I get the error
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: 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 <20060209> in contactdate Column. Expected type is DateTime.
If i change the value 20060209 to something like 2006-02-09 12:35:29.998 it
inserts fine, however when i use an insert statement the data 20060209
inserts just fine. Why?
Here's a snippet of my program:
string strTableToLoad = "SELECT * FROM " + strLoadTable ;
SqlCommand cmdTableToLoad = new SqlCommand (strTableToLoad,DWConnection);
DataTable tblToLoad = new DataTable(strLoadTable);
SqlCommand cmdTableToLoad = new SqlCommand (strTableToLoad,DWConnection);
da.SelectCommand = cmdTableToLoad;
da.FillSchema(dsInfo, SchemaType.Source, strLoadTable);
da.Fill(dsInfo);
Console.WriteLine("Columns: " + tblToLoad.Columns.Count);
dsInfo.Tables[strLoadTable].LoadDataRow(strTokens,false);