I am trying to delete some data in column (Delta_sigma) by comparing it with value entered in textbox but i get error Cannot perform '<' operation on System.Double and System.String.
DataColumn Delta_sigma = table1.Columns.Add("Delta_Sigma", typeof(double));
Delta_sigma.Expression = "(Convert(Median,'System.Double') - Convert(Median_Refrence,'System.Double')) / (sigma_Refrence)";
double delta_sigma_critical = double.Parse(textBox1.Text);
DataRow[] rows4;
rows4 = table1.Select(" Delta_sigma < delta_sigma_critical ");
foreach (DataRow r in rows4)
r.Delete();
Loading

VulpesPosted Apr 25, 2014, 7:41 PM
Farhan ShariffPosted Apr 30, 2014, 8:36 AM
VulpesPosted Apr 30, 2014, 6:01 AM
Farhan ShariffPosted Apr 30, 2014, 3:41 AM
VulpesPosted Apr 28, 2014, 8:13 AM
It's a point worth remembering as it can lead to difficult to find bugs if you don't spot it early.
Farhan ShariffPosted Apr 28, 2014, 3:22 AM
VulpesPosted Apr 27, 2014, 3:17 PM
If you're deleting multiple elements, it's therefore easier to iterate backwards through the collection because each time you delete an element it won't affect the indices of the elements which are still to be examined.
Farhan ShariffPosted Apr 27, 2014, 11:38 AM
Farhan ShariffPosted Apr 25, 2014, 9:26 AM
double Non_critical_cpk = double.Parse(textBox2.Text);//ideal value =6
Convert.ToDouble(Non_critical_cpk);
for (int v = table1.Rows.Count - 1; v >= 0; v--)
{
double c = Convert.ToDouble(table1.Rows[v]["CpK_Refrence"].ToString());
double c1 = Convert.ToDouble(table1.Rows[v]["CpK"].ToString());
if (c > (Non_critical_cpk) && c1 > (Non_critical_cpk))
{
table1.Rows.RemoveAt(v);
}
}
//-----------part2 -------
Farhan ShariffPosted Apr 25, 2014, 5:10 AM
columns (Delta_sigma,CpK,CpK_Refrence)
text box(delta_sigma_critical,Non_critical_cpk,critical_cpk).
double delta_sigma_critical = double.Parse(textBox1.Text);
double Non_critical_cpk = double.Parse(textBox2.Text);//ideal value =6
double critical_cpk = double.Parse(textBox3.Text);//Ideal value = 1.6
//-----------------------------------------------------------------------------------
// --part1
DataView dv = table1.DefaultView;
dv.RowFilter = "NOT(CpK_Refrence > Non_critical_cpk AND CpK >Non_critical_cpk)";
table1 = dv.ToTable();
//-------------------------------------------------------------------------------------
//----------------------part2
DataView dv1 = table1.DefaultView;
dv1.RowFilter = "CpK < critical_cpk AND Delta_Sigma > delta_sigma_critical";
DataTable dt2 = dv1.ToTable();
dv1.RowFilter = "NOT(CpK < critical_cpk AND Delta_Sigma > delta_sigma_critical)";
DataTable dt3 = dv1.ToTable();
dt2.Merge(dt3);
table1 = dt2;
dv1 = null;
dt2 = dt3 = null;
Farhan ShariffPosted Apr 25, 2014, 4:36 AM
VulpesPosted Apr 24, 2014, 11:59 AM
Try this code instead:
double delta_sigma_critical = double.Parse(textBox1.Text);
for(int i = table1.Rows.Count - 1; i >= 0; i--) //EDITED
{
double d = Convert.ToDouble(table1.Rows[i]["Median"].ToString()) - Convert.ToDouble(table1.Rows[i]["Median_Refrence"].ToString());
d /= Convert.ToDouble(table1.Rows[i]["sigma_Refrence"].ToString());
if (d < delta_sigma_critical) table1.Rows.RemoveAt(i);
}