Groups | Blog | Home
all groups > dotnet ado.net > february 2008 >

dotnet ado.net : Problem with AdomdCommand when Passing DataTable with DBNull's


Cor Ligthert[MVP]
2/27/2008 12:00:00 AM
Nestor,

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

Cor

"Nestor" <nestor@nsuli.com> schreef in bericht
news:1511F76B-CCAD-41DC-99A3-1878D8AC17E8@microsoft.com...
[quoted text, click to view]
Nestor
2/27/2008 7:46:55 PM
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
2/28/2008 10:17:22 AM
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."

[quoted text, click to view]
Cor Ligthert [MVP]
3/5/2008 1:07:02 PM
[quoted text, click to view]

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

AddThis Social Bookmark Button