P
Pedro \Shade\ Miller
Hi guys,
I'm facing a very puzzling problem and thought maybe someone here
could help. It's been driving me nuts, really.
I'm developing a Windows CE application (to be deployed in Windows CE
4.2 core) and my emulator is running Windows CE .NET v4.10 (build
908). I don't have a device with me now where I could test the
software, unfortunately (that's still being arranged).
One of the code bits is a button to consolidate data, merging rows in
a DataTable:
Please forgive the commented extra code, I've been adding and removing
scaffolding looking for the problem.
What this does is something like this: suppose you have three rows,
thus:
A 0 0 7
B 4 3 0
A 0 0 3
C 1 5 0
A 2 2 0
It consolidates the same products to:
A 2 2 10
B 4 3 0
It works when you only have one product repeated (i.e., only one row1
is updated). However, if there are several repeated products,
A 0 0 7
B 0 0 5
A 2 2 0
B 4 3 0
the system crashes with a native exception (code 0xC0000005, which
research shows is an illegal memory access exception) when I try to
update the second row in the table (line marked "CRASH!", above). Note
that the first update goes well! Also, if I set it up with only one
product repeated, press the button, set it up with another product
repeated, and press the button again, it works.
I'm guessing it has to do with the way DataTable updates its rows, but
so far, I've had no luck figuring the problem out. I'll greatly
appreciate any help I can get!
Thanks in advance,
Shade.
I'm facing a very puzzling problem and thought maybe someone here
could help. It's been driving me nuts, really.
I'm developing a Windows CE application (to be deployed in Windows CE
4.2 core) and my emulator is running Windows CE .NET v4.10 (build
908). I don't have a device with me now where I could test the
software, unfortunately (that's still being arranged).
One of the code bits is a button to consolidate data, merging rows in
a DataTable:
Code:
private void btnConsolidar_Click(object sender, System.EventArgs e)
{
for( int j=0; j < dataTable.Rows.Count; j++ )
{
DataRow row1 = dataTable.Rows[j];
String ean = (String)row1["ean"];
String cod = (String)( ( row1["codigo"] == null ) ? "" :
row1["codigo"] );
int idx;
for( idx=j+1; idx < dataTable.Rows.Count; idx++ )
{
DataRow row2 = dataTable.Rows[idx];
if( ((String)row2["ean"]) == ean || (cod != "" &&
((String)row2["codigo"]) == cod ))
{
long q1 = long.Parse((string)row1["quant"]);
long q2 = long.Parse((string)row2["quant"]);
if( bConferencia )
{
if( (string)row1["quant1"] == "0" )
{
string q =
(string)row2["quant1"];
//row1["quant1"] = q;
dataTable.Rows[j]["quant1"] = q; // CRASH!
}
if( (string)row1["quant2"] == "0" )
//row1["quant2"] = (string)row2["quant2"];
dataTable.Rows[j]["quant2"] =
(string)row2["quant2"];
}
row1["quant"] = q1+q2;
// remove a fileira copiada
dataTable.Rows.RemoveAt( idx );
//dataTable.AcceptChanges();
// row1 = dataTable.Rows[j];
// compensa a fileira removida
idx--;
}
}
}
dgItens.DataSource = dataTable;
dgItens.Refresh();
}
Please forgive the commented extra code, I've been adding and removing
scaffolding looking for the problem.
What this does is something like this: suppose you have three rows,
thus:
A 0 0 7
B 4 3 0
A 0 0 3
C 1 5 0
A 2 2 0
It consolidates the same products to:
A 2 2 10
B 4 3 0
It works when you only have one product repeated (i.e., only one row1
is updated). However, if there are several repeated products,
A 0 0 7
B 0 0 5
A 2 2 0
B 4 3 0
the system crashes with a native exception (code 0xC0000005, which
research shows is an illegal memory access exception) when I try to
update the second row in the table (line marked "CRASH!", above). Note
that the first update goes well! Also, if I set it up with only one
product repeated, press the button, set it up with another product
repeated, and press the button again, it works.
I'm guessing it has to do with the way DataTable updates its rows, but
so far, I've had no luck figuring the problem out. I'll greatly
appreciate any help I can get!
Thanks in advance,
Shade.