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


VulpesRank #55 · 29.2K reputationPosted Apr 25, 2014, 3:41 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 24, 2014, 7:59 AM EDT
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);
}
Farhan ShariffRank #2,004 · 725 reputationPosted Apr 25, 2014, 12:36 AM EDT
Farhan ShariffRank #2,004 · 725 reputationPosted Apr 25, 2014, 1:10 AM EDT
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 ShariffRank #2,004 · 725 reputationPosted Apr 25, 2014, 5:26 AM EDT
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 ShariffRank #2,004 · 725 reputationPosted Apr 27, 2014, 7:38 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 27, 2014, 11:17 AM EDT
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 ShariffRank #2,004 · 725 reputationPosted Apr 27, 2014, 11:22 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 28, 2014, 4:13 AM EDT
It's a point worth remembering as it can lead to difficult to find bugs if you don't spot it early.
Farhan ShariffRank #2,004 · 725 reputationPosted Apr 29, 2014, 11:41 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 30, 2014, 2:01 AM EDT
Farhan ShariffRank #2,004 · 725 reputationPosted Apr 30, 2014, 4:36 AM EDT