ng80092b
ng80092b

Reputation: 667

How to properly write a datatable.Compute(string) when it gives a undetailed error?

I'm creating a data table with doubles, like this

enter image description here

And i'm using another double that depends on user input to fix itself the 2 immediate above, and 2 immediate below rows.

double razao = Variables.dadocobplanaW / Variables.alturaW;

 double min = Convert.ToDouble(DataAccess.Instance.tabelaplanaplatibandaW.Compute("MIN(Variavel)", "Variavel > " + razao.ToString()));
 double max = Convert.ToDouble(DataAccess.Instance.tabelaplanaplatibandaW.Compute("MAX(Variavel)", "Variavel < " + razao.ToString()));


 DataRow[] rows = DataAccess.Instance.tabelaplanaamansardadaW.Select("Variavel = " + min.ToString() + " OR " + "Variavel = " + max.ToString());

I already re-verified the tables, and their names, and everything is right, the code runs, but when i get a value into razao the program will crash when trying to find min and max

Is it because I have 2 lines with the same Variavel on every case?

Any hint?

Edit: here's the error message

enter image description here

Upvotes: 0

Views: 1013

Answers (2)

ASh
ASh

Reputation: 35681

The problem can be caused by incorrect format of razao.ToString(), min.ToString(), max.ToString(); check the delimiter in those strings. It should be '.', I suppose.
If you have comma ','; try this razao.ToString(CultureInfo.InvariantCulture)

Upvotes: 2

shA.t
shA.t

Reputation: 16958

I think your problem is about parsing expressions used by compute() method.

You can verify it by using below code, and seems you don't need doubles!

String min = DataAccess.Instance.tabelaplanaplatibandaW.Compute("MIN(Variavel)", String.Format(@"Variavel > {0}", razao.ToString())).ToString();

After that you need to find the behind code of compute() method. That method uses an expression parser that probably read data from your table and parse it to a node of System.Data. DataColumn.Expression Property

The problem is in filter part and when Variavel and razao are parsing to System.Double.

In Above link says :

For example, if the number in the literal is 2147483650, DataSet will first attempt to parse the number as an Int32. This will not succeed because the number is too large. In this case DataSet will parse the number as an Int64, which will succeed. If the literal was a number larger than the maximum value of an Int64, DataSet will parse the literal using Double. Real literals using scientific notation, such as 4.42372E-30, are parsed using System.Double.

Anyway you can change your way, and take the Min and Max from DB. That I usually use it.

Upvotes: 1

Related Questions