Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();
Posted

Quote:
Cannot perform '<' operation on System.Double and System.String.
Quite clear. You cannot compare data of different types.

So, try to compare data with same type.
 
Share this answer
 
Comments
FarhanShariff 25-Apr-14 3:32am    
I know that how to do that?
I guess it should look like...

rows4 = table1.Select("Delta_sigma < " + delta_sigma_critical);
foreach (DataRow r in rows4)
r.Delete();

Try and let me know.
FarhanShariff 25-Apr-14 4:43am    
select cannot use 'external' varibale
Okay. I think you did it in a other way by looping. Good. :)
FarhanShariff 25-Apr-14 7:16am    
please check this http://www.codeproject.com/Questions/764845/compare-textbox-value-with-DataTable-column
C#
double delta_sigma_critical = double.Parse(textBox1.Text);

for(int i = table1.Rows.Count - 1; i >= 0; i--)
{
   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);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900