Is there any way to alleviate that so it will go thru even there is a non-numeric value for PropertyCode. Basically can the code I provided by changed for PropertyCode?
Change the datatype of id to something that allowed character values (i.e. string).
Change the query to always return a numeric value
SELECT CASE WHEN TRY_CONVERT(int, PropertyCode) IS NULL
THEN -1
ELSE CONVERT(int, PropertyCode)
END AS PropertyCodeNumeric
Use the typeParse method (warning: This syntax should be close, but may not be 100% correct. test thoroughly)
bool checkInt = Int32.TryParse(await reader.GetFieldValueAsAsync(0), out Id);
Personally, I’d change the field type in the code since that matches what’s in the database. Shoehorning something into a specific time is usually dangerous and troublesome.
NOTE: I would also suggest using variable names which matches the result set out of your database. It will save confusion later, and reduces the chances of non-matching data types. Putting PropertyCode into id will undoubtedly cause you confusion later.
Then I would venture you’re getting a null value returned from your code somewhere. I would suggest debugging your code to see what is actually in reader.GetFieldValueAsync(0)
I figured out what it was. My SQL syntax was incorrect. Instead of having it in parentheses I removed the parentheses and the single quotes around each field and it worked!