Problem with AdomdCommand when Passing DataTable with DBNull's

  • Thread starter Thread starter Nestor
  • Start date Start date
N

Nestor

The following code would fail, with the error:

"The '' string cannot be converted to the double type."

when trainTable contains rows with DBNull in some of the columns.
How can I pass NULL to MSAS?

using (AdomdCommand comm = connAS.CreateCommand())
{
comm.CommandText = "INSERT INTO MINING MODEL [MyModel]
([statbbrev],[lpop],[ldem],[lemp]) @TrainTable";
comm.Parameters.Add("TrainTable", trainTable);
comm.ExecuteNonQuery();
}
 
Nestor,

A string can simply not contain DBNull.Value, I would try it with using an
object.

Cor
 
I'm not sure what you are suggesting.
the table trainTable is a DataTable with columns of type Double. As such, of
course you can assign DBNull.Value to it (that's why they have the method
IsNull(..) in the DataRow object.
Nestor

ps: Just for the heck of it, I tried changing the type of the column to
Object, but this time I got the exception "Object reference not set to an
instance of an object."

Cor Ligthert said:
Nestor,

A string can simply not contain DBNull.Value, I would try it with using an
object.

Cor

Nestor said:
The following code would fail, with the error:

"The '' string cannot be converted to the double type."

when trainTable contains rows with DBNull in some of the columns.
How can I pass NULL to MSAS?

using (AdomdCommand comm = connAS.CreateCommand())
{
comm.CommandText = "INSERT INTO MINING MODEL [MyModel]
([statbbrev],[lpop],[ldem],[lemp]) @TrainTable";
comm.Parameters.Add("TrainTable", trainTable);
comm.ExecuteNonQuery();
}
 
the table trainTable is a DataTable with columns of type Double. As such,
of course you can assign DBNull.Value to it

As you say it, I never knew that a double could be DBNull.Value a
DBNull.Value is a value type you know like double. However, probably
something new.

Cor
 
Back
Top