Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string strLot = "Lot = '" + textBox1.Text + "'";
                    
                    string strsearchLot = textBox1.Text;
                    dtsearchLot = null;
                    rows = dt.Select(strsearchLot);

                    if (rows != null && rows.Length > 0)
                    {
                        dtsearchLot = rows.CopyToDataTable();
                    }

                    cnt++;


Hi! I wrote this code to search for a particular "lot number" from my excel sheet. However, I got an error of "value is either too big or too small for a double" at
C#
rows = dt.Select(strsearchLot); 


The row number for the "strsearchLot" from the excel sheet is stated as row 668.
May I know how to solve this issue? Thank you in advance for the help.

What I have tried:

I've tried to change the row number to a smaller number but still have that error.
Posted
Updated 9-Apr-18 22:47pm
v2
Comments
Jochen Arndt 10-Apr-18 3:28am    
Are you sure that the error occurs on that line and not on the next containing rows.CopyToDataTable()?
Member 13650651 10-Apr-18 3:43am    
my bad, the error is actually at "rows = dt.Select(strsearchLot);"
Maciej Los 10-Apr-18 4:16am    
What;s your input data in a datatable?
Jochen Arndt 10-Apr-18 4:18am    
Open the sheet with Excel and check the columns in that row. There is probably a cell containing a value that can't be represented as a vaild double.
F-ES Sitecore 10-Apr-18 4:32am    
Given we don't know what type "rows" is or what it contains, we don't know what "dt" is, we don't know what "Select" is or what it does or what parameters it uses, and we don't have access to your data it's not really a question anyone can answer, we can only guess. As the error message suggests there is probably a number in your sheet that is too big or too small to be stored in a .net double variable.

1 solution

An error message is self-explanatory.

As an official documentation[^] states:
Quote:
Real literals using scientific notation, such as 4.42372E-30, are parsed using System.Double.

Real literals without scientific notation, but with a decimal point, are treated as System.Decimal. If the number exceeds the maximum or minimum values supported by System.Decimal, then it is parsed as a System.Double. For example:

142526.144524 will be converted to a Decimal.

345262.78036719560925667 will be treated as a Double.


BTW: your code is probably wrong!
C#
string strLot = "Lot = '" + textBox1.Text + "'"; //this seems to be OK!
string strsearchLot = textBox1.Text;//this is probably wrong, unless a TextBox1.Text contains: Lot=<SomeDecimalValue>!
rows = dt.Select(strsearchLot); //if textBox1.Text does not contains field name and proper comparison operator, it'll cause error "The expression '<ValueFromTextBox>' does not return a boolean.":
 
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