Problem converting type
Hi all,
Got a very simple task to do, but I have not been able to get it done. It is driving me crazy !!!
I am doing a invoice sw. I need to pull out the last invoice number(ie the largest number) from the db, and add 1 to it to generate the next invoice number. So far, I have had no problem retriving the last invoice number from the db into a dataset. But when I try to add 1 to it ... it gives me the error "System.InvalidCastException: Cast from type 'DBNull' to type 'Integer' is not valid."
My code is as follows :
dim tmp_inv_no2 as integer
ds = SelectRows(ds,inv_conn_str,mysql,"inv")
tmp_inv_no2 = ds.tables("inv").compute("MAX(inv_no)","")
inv_no.text = tmp_inv_no2
But when I changed my code to the following ...
dim tmp_inv_no2 as string
ds = SelectRows(ds,inv_conn_str,mysql,"inv")
tmp_inv_no2 = ds.tables("inv").compute("MAX(inv_no)","").tostrin g()
inv_no.text = tmp_inv_no2
I can display the last invoice number with no problem !! Therefore, it is not a NULL value.
I next tried to convert the string to a integer by using the following code ...
dim tmp_inv_no2 as string
dim tmp_inv_no3 as integer
ds = SelectRows(ds,inv_conn_str,mysql,"inv")
tmp_inv_no2 = ds.tables("inv").compute("MAX(inv_no)","").tostrin g()
tmp_inv_no3 = cint(tmp_inv_no2)
I get an error message
System.FormatException: Input string was not in a correct format.
Please help
