Last post Mar 08, 2017 02:34 AM by Rednuts72
Mar 07, 2017 12:25 AM|Rednuts72|LINK
I'm trying to use a value of a field of a database table in a calcul operator variable and I've got the following error message :
Exception Details: System.FormatException: Input string was not in a correct format.
The code is :
DataSourceSelectArguments args1 = new DataSourceSelectArguments();
SqlDataSource3.SelectCommand = "SELECT T_JP_Cmde_NumCle FROM t_jp_commande ORDER BY idT_JP_Cmde DESC LIMIT 1"; // Value of T_JP_Cmde_NumCle is '171990001' VARCHAR(22)
DataView DtView2 = (DataView)SqlDataSource2.Select(args1);
DataTable DtTable2 = DtView2.ToTable();
int IntLastNumCleCmde = Convert.ToInt32(DtTable2.Rows.ToString()); // error message
int IntNvNumcleCmde = IntLastNumCleCmde + 1;
Mar 07, 2017 06:37 AM|raju dasa|LINK
Follow below steps to debug:
Mar 07, 2017 08:36 AM|Cathy Zou|LINK
The reason for your problem, You can't convert a null value to a meaningful value through
So, Please to check the value in DtTable2.Rows. whether is it null? or it it could be convert to int type:
Note: Convert method is used to converts the specified string representation of a number to an equivalent 32-bit signed integer.
I suggest you could use Int32.TryParse() method.
Something as below:
if(Int32.TryParse(DtTable2.Rows.ToString(), out IntLastNumCleCmde))
int IntNvNumcleCmde = IntLastNumCleCmde + 1; SqlDataSource3.Dispose();}
Mar 07, 2017 10:00 AM|Rednuts72|LINK
I don't find the "quick watch" function ?
Mar 07, 2017 10:08 AM|raju dasa|LINK
Check this site for QuickWatch steps:
Mar 08, 2017 02:28 AM|Cathy Zou|LINK
Are you solve your problem?
If not, as I suggested in my first reply, you need to check the value in Rows to make sure it isn’t null and it could be converted to int type.
You also could use Int32.TryParse() method. Int32.TryParse() method Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the operation succeeded.
Mar 08, 2017 02:34 AM|Rednuts72|LINK
The problem is solved. Wiith the TryParse function, I could saw that the Row0 value is null. I update the query.
Truly yours !