LoadDatarow DataReader Cast Error

  • Thread starter news.microsoft.com
  • Start date
N

news.microsoft.com

Im am trying to load a Data from a DataReader into a DataTable with the
following code. I am getting a cast error at the LoadDataRow statement.

while(reader.Read())
{
object[] rowobjects = new
object[ratestructurecompound._DataTable_RateStructureTbl.Columns.Count];
reader.GetSqlValues(rowobjects);


ratestructurecompound._DataTable_RateStructureTbl.LoadDataRow(rowobjects,
true);
}

Here is the error message:
"System.InvalidCastException: Specified cast is not valid.\r\n at
System.Convert.ToDateTime(Object value)\r\n at
System.Data.Common.DateTimeStorage.Set(Int32 record, Object value)\r\n
at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't
store <4/5/2004 3:04:00 PM> in CreateDatetime Column. Expected type is
DateTime."

I thought this method was suppose to cast properly.
 
T

TJO

news.microsoft.com said:
Im am trying to load a Data from a DataReader into a DataTable with the
following code. I am getting a cast error at the LoadDataRow statement.

while(reader.Read())
{
object[] rowobjects = new
object[ratestructurecompound._DataTable_RateStructureTbl.Columns.Count];
reader.GetSqlValues(rowobjects);


ratestructurecompound._DataTable_RateStructureTbl.LoadDataRow(rowobjects,
true);
}

Here is the error message:
"System.InvalidCastException: Specified cast is not valid.\r\n at
System.Convert.ToDateTime(Object value)\r\n at
System.Data.Common.DateTimeStorage.Set(Int32 record, Object value)\r\n
at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't
store <4/5/2004 3:04:00 PM> in CreateDatetime Column. Expected type is
DateTime."

I thought this method was suppose to cast properly.

Need to use GetValues instead of GetSqlValues! ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top