Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How to fix "Input string was not in a correct format" error when an empty value(or a null value) is returned from an Int type method??Pls Help

$
0
0

Hi All,

I have a method (getMaxID) which reads a SQL table (myTable) and returns a value from it. The SQL table has two columns which are "ID" (Int type and primary key) and "Total" (Int type).

The SQL table reads all the values from "Total" column, finds the maximum value, and returns the "ID" which corresponds to the maximum value. 

For example, if myTable has following three rows, my method getMaxID returns 2 (since 10 is the maximum value in Total column and 2 is the ID which corresponds to 10 )

ID        Total

1            5

2           10

3             7

However, there can be instances where myTable would be totally empty(Which means there is no data in it).

In such cases, when I call getMaxID, I get "Input string was not in a correct format" error.

I want getMaxID to return 0 in such instances. 

Can someone please let me know how to do this in C#?

Thank you very much.

Kind regards,

Clive


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>