Odd Behavior Copying VarBinary Data

E

Eric

I'm copying the content from one DataTable to another. Both tables have a
SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

The problem I'm seeing is that the data seems to be duplicated.

So, if the both rows contained the value "1 2 3" after the copy I'm seeing a
value of "1 1 2 2 3 3" in the row where the data was copied to.


Any thoughts ideas are appreciated.
 
W

W.G. Ryan - MVP

Comments below:
Eric said:
I'm copying the content from one DataTable to another. Both tables have a
SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

There could be a problem with the encoding but i'm not positive without
looking at the code.

In the following snippet, the assertion passes, is this essentially what
you're doing?

private void button7_Click(object sender, System.EventArgs e)
{
DataColumn dc = new DataColumn("Cuckoo", typeof(System.Byte[]));
DataTable dt = new DataTable("EDC");
dt.Columns.Add(dc);
DataRow dro = dt.NewRow();
dro[0] = "CuckoozRule".ToCharArray();
dt.Rows.Add(dro);
dro = dt.NewRow();
dro[0] = dt.Rows[0][0];
dt.Rows.Add(dro);
Debug.Assert(dt.Rows[0][0] == dt.Rows[1][0], "Da rows don't match");
}
 
E

Eric

Ryan,
Thanks for the response. I'm not even doing anything that complex.
Both DataTables are filled from their respective tables from different
databases. Then I'm just doing a loop copying one to another. Below is the
exact code.

if(drDest.Table.Columns.Contains(strColName))
{
bool bReadOnly = drDest.Table.Columns[strColName].ReadOnly;
if(!bReadOnly)
drDest[strColName] = drSource[strColName];
}

W.G. Ryan - MVP said:
Comments below:
Eric said:
I'm copying the content from one DataTable to another. Both tables have
a SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

There could be a problem with the encoding but i'm not positive without
looking at the code.

In the following snippet, the assertion passes, is this essentially what
you're doing?

private void button7_Click(object sender, System.EventArgs e)
{
DataColumn dc = new DataColumn("Cuckoo", typeof(System.Byte[]));
DataTable dt = new DataTable("EDC");
dt.Columns.Add(dc);
DataRow dro = dt.NewRow();
dro[0] = "CuckoozRule".ToCharArray();
dt.Rows.Add(dro);
dro = dt.NewRow();
dro[0] = dt.Rows[0][0];
dt.Rows.Add(dro);
Debug.Assert(dt.Rows[0][0] == dt.Rows[1][0], "Da rows don't match");
}
The problem I'm seeing is that the data seems to be duplicated.

So, if the both rows contained the value "1 2 3" after the copy I'm
seeing a value of "1 1 2 2 3 3" in the row where the data was copied to.


Any thoughts ideas are appreciated.
 
W

W.G. Ryan - MVP

Eric, if you would, change the code as indicated below and tell me what
happens.
Eric said:
Ryan,
Thanks for the response. I'm not even doing anything that complex.
Both DataTables are filled from their respective tables from different
databases. Then I'm just doing a loop copying one to another. Below is
the
exact code.

if(drDest.Table.Columns.Contains(strColName))
{
bool bReadOnly = drDest.Table.Columns[strColName].ReadOnly;
if(!bReadOnly)
drDest[strColName] = drSource[strColName];
Debug.Assert( drDest[strColName] = drSource[strColName]; //These should
match - but if I understood you correctly they aren't, is that right? If
so, tell me if the assertion failes.
}

W.G. Ryan - MVP said:
Comments below:
Eric said:
I'm copying the content from one DataTable to another. Both tables have
a SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

There could be a problem with the encoding but i'm not positive without
looking at the code.

In the following snippet, the assertion passes, is this essentially what
you're doing?

private void button7_Click(object sender, System.EventArgs e)
{
DataColumn dc = new DataColumn("Cuckoo", typeof(System.Byte[]));
DataTable dt = new DataTable("EDC");
dt.Columns.Add(dc);
DataRow dro = dt.NewRow();
dro[0] = "CuckoozRule".ToCharArray();
dt.Rows.Add(dro);
dro = dt.NewRow();
dro[0] = dt.Rows[0][0];
dt.Rows.Add(dro);
Debug.Assert(dt.Rows[0][0] == dt.Rows[1][0], "Da rows don't match");
}
The problem I'm seeing is that the data seems to be duplicated.

So, if the both rows contained the value "1 2 3" after the copy I'm
seeing a value of "1 1 2 2 3 3" in the row where the data was copied to.


Any thoughts ideas are appreciated.
 
E

Eric

Ryan,
Unfortunately I don't currently have access to the DBs I need, so I
have to test this tommorow.

Thanks again for your help.

W.G. Ryan - MVP said:
Eric, if you would, change the code as indicated below and tell me what
happens.
Eric said:
Ryan,
Thanks for the response. I'm not even doing anything that complex.
Both DataTables are filled from their respective tables from different
databases. Then I'm just doing a loop copying one to another. Below is
the
exact code.

if(drDest.Table.Columns.Contains(strColName))
{
bool bReadOnly = drDest.Table.Columns[strColName].ReadOnly;
if(!bReadOnly)
drDest[strColName] = drSource[strColName];
Debug.Assert( drDest[strColName] = drSource[strColName]; //These
should match - but if I understood you correctly they aren't, is that
right? If so, tell me if the assertion failes.
}

W.G. Ryan - MVP said:
Comments below:
I'm copying the content from one DataTable to another. Both tables
have a SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

There could be a problem with the encoding but i'm not positive without
looking at the code.

In the following snippet, the assertion passes, is this essentially what
you're doing?

private void button7_Click(object sender, System.EventArgs e)
{
DataColumn dc = new DataColumn("Cuckoo", typeof(System.Byte[]));
DataTable dt = new DataTable("EDC");
dt.Columns.Add(dc);
DataRow dro = dt.NewRow();
dro[0] = "CuckoozRule".ToCharArray();
dt.Rows.Add(dro);
dro = dt.NewRow();
dro[0] = dt.Rows[0][0];
dt.Rows.Add(dro);
Debug.Assert(dt.Rows[0][0] == dt.Rows[1][0], "Da rows don't match");
}

The problem I'm seeing is that the data seems to be duplicated.

So, if the both rows contained the value "1 2 3" after the copy I'm
seeing a value of "1 1 2 2 3 3" in the row where the data was copied
to.


Any thoughts ideas are appreciated.
 
E

Eric

Ryan,
My test using Debug.Assert did not reveal any differences in my
VarBinary Columns, however it did produce some strange results on int and
boolean columns.

Several of the rows with these column types failed the assert.
Debug.Assert(drDest[strColName] == drSource[strColName],strColName+" No
Match - Source: "+drSource[strColName].ToString()+" Dest:
"+drDest[strColName].ToString());

But based on my code above, the display showed the exact same values and
each column had the exact same datatype. Weird.


W.G. Ryan - MVP said:
Comments below:
Eric said:
I'm copying the content from one DataTable to another. Both tables have
a SQL column of type VarBinary.

The data is actually copied this way.

DataRow[Column] = DataRow[Column];

Would this method cause a problem with VarBinary data types?

There could be a problem with the encoding but i'm not positive without
looking at the code.

In the following snippet, the assertion passes, is this essentially what
you're doing?

private void button7_Click(object sender, System.EventArgs e)
{
DataColumn dc = new DataColumn("Cuckoo", typeof(System.Byte[]));
DataTable dt = new DataTable("EDC");
dt.Columns.Add(dc);
DataRow dro = dt.NewRow();
dro[0] = "CuckoozRule".ToCharArray();
dt.Rows.Add(dro);
dro = dt.NewRow();
dro[0] = dt.Rows[0][0];
dt.Rows.Add(dro);
Debug.Assert(dt.Rows[0][0] == dt.Rows[1][0], "Da rows don't match");
}
The problem I'm seeing is that the data seems to be duplicated.

So, if the both rows contained the value "1 2 3" after the copy I'm
seeing a value of "1 1 2 2 3 3" in the row where the data was copied to.


Any thoughts ideas are appreciated.
 

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

Similar Threads


Top