DataSet loses original value across an interface

C

codefragment

Hi
I have a dataset which holds (amongest other things) a string.
- The dataset gets loaded from the database via a middle tier
- The string value contains "\r\n"
- Its serialised to the web application
- The web application deletes the row. I can see using the below that
before and after the delete the
string value is what it should be

(string)rows[0]["TEXT", DataRowVersion.Original];

In the middle tier however after serializing back that same line now
returns an empty string? The other columns are fine and if I put a
value other than "\r\n" in (e.g. "\r\na") then its fine. The string
column is allowed to be null.

Does this make sense to anyone?

ta
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I do not understand your post, you say that you delete the post. Then later
you talk about serialization back in the middle tier.

Are you sending back the dataset?
after you delete the row?
IIRC the deleted rows will not be serialized.
 
C

codefragment

I do not understand your post, you say that you delete the post. Then later
you talk about serialization back in the middle tier.

I delete a row in a DataSet using row.Delete(). Then the dataset is
sent back to the middle tier. Even though
a row is deleted I would expect to be able to access the original
values until AcceptChanges is called
or the DataSet is put to the database by the DataAdapter, and I can
except in this one odd case.
Are you sending back the dataset?
after you delete the row?
IIRC the deleted rows will not be serialized.

The deleted rows are serialised. The other columns still hold their
original values. So does this row if I put
some other characters in.

I also did an experiment using memory streaming and it had the same
effect, heres the code.



MemoryStream stream = new MemoryStream(1000000);

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
bformatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

bformatter.Serialize(stream, theDs);

//de
stream.Seek(0, SeekOrigin.Begin);

bformatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

theDs = (MyDsClass)bformatter.Deserialize(stream);
stream.Close();
 
C

codefragment

Hi
I did a complete, seperate example. Place the logic below in some
file, use right click and resolve to get the 'using'
statements in there and give it a whirl.
The variables text1 and text2 are exactly what you would think the
first time but although text1 is set text2 is empty after serializing/
deserializing

ta


DataSet dataSet = new DataSet();
DataTable table = dataSet.Tables.Add();
table.Columns.Add("normalString", typeof(string));
table.Columns.Add("oddString", typeof(string));
DataRow row = table.NewRow();
table.Rows.Add(row);

row["normalString"] = "hello world";
row["oddString"] = "\r\n";

dataSet.AcceptChanges();
row.Delete();

foreach (DataRow itRow in dataSet.Tables[0].Rows)
{
if (itRow.RowState == DataRowState.Deleted)
{
string text1 = (string)itRow["normalString",
DataRowVersion.Original];
string text2 = (string)itRow["oddString",
DataRowVersion.Original];
}
}

MemoryStream stream = new MemoryStream(1000000);

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
bformatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

bformatter.Serialize(stream, dataSet);

//de
stream.Seek(0, SeekOrigin.Begin);

bformatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

DataSet newDs = (DataSet)bformatter.Deserialize(stream);

foreach(DataRow itRow in newDs.Tables[0].Rows)
{
if (itRow.RowState == DataRowState.Deleted)
{
string text1 = (string)itRow["normalString",
DataRowVersion.Original];
string text2 = (string)itRow["oddString",
DataRowVersion.Original];
}
}
stream.Close();
 

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