Help....

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;
}
}

[1913 byte] By [pexxx] at [2007-12-22]
# 1
Is there a way to work around this problem?
pexxx at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified