Merge binary serialized nullable datetime field

  • Thread starter Thread starter Perry van Kuppeveld
  • Start date Start date
P

Perry van Kuppeveld

Hello,

If i merge a dataset with a binary deserialized dataset containing a
nullable datetime field, the merged values is not null anymore. If i merge a
xml deserialized dataset there's no problem.

How can i merge a binary serialized dataset with nullable datetime fields?

Console app sample:

class Program
{
static void Main(string[] args)
{
// switch this bool for testing
bool datasetBin = true;
DataSet ds = CreateEmptyDataset(datasetBin);
ds.Tables["Test"].Rows.Add(new object[] { null });
Console.WriteLine("Value of row 0, column 0:
{0}",ds.Tables["Test"].Rows[0].IsNull(0) ? "Null" :
ds.Tables["Test"].Rows[0][0]);
// serialize
BinaryFormatter frmt = new BinaryFormatter();
Stream fileOut = new FileStream(@"c:\temp.tmp",
FileMode.Create);
frmt.Serialize(fileOut, ds);
fileOut.Close();
// deserialize
Stream fileIn = new FileStream(@"c:\temp.tmp", FileMode.Open);
DataSet dsRead = frmt.Deserialize(fileIn) as DataSet;
fileIn.Close();
// merge serialized dataset
DataSet dsMerged = CreateEmptyDataset(datasetBin);
dsMerged.Merge(dsRead);
Console.WriteLine("Value of merged row 0, column 0: {0}",
dsMerged.Tables["Test"].Rows[0].IsNull(0) ? "Null" :
dsMerged.Tables["Test"].Rows[0][0]);
Console.ReadLine();
}

private static DataSet CreateEmptyDataset(bool datasetBin)
{
DataSet ds = new DataSet();
DataTable table = ds.Tables.Add("Test");
DataColumn col = table.Columns.Add("Date",typeof(DateTime));
col.AllowDBNull = true;
ds.RemotingFormat = datasetBin ? SerializationFormat.Binary :
SerializationFormat.Xml;
return ds;
}
}
 
Hello,

I have the same problem when deserializing a binary serialized dataset
coming from my remoting layer.

I have found that it is a known issue there:
http://support.microsoft.com/default.aspx?scid=kb;en-us;913766&sd=rss&spid=8291

With title: A DateTime column that does not contain any data is incorrectly
represented by a DateTime.MinValue field when a .NET Framework 2.0 DataSet
object is deserialized on a client computer

I've tried to download the hotfix but it doesn't work, it tells me something
about the installation source, here's the message I get in spanish (my os
language, but I have the english framework installed...):
El origen de instalación de este producto no está disponible. Compruebe que
el origen existe y que puede obtener acceso a él.

Thank you.
 
Back
Top