The message tells you that you are using a reference that has not been initialise to an object. So look at the line that the error occurs on to find out why.
Also do not use
Convert.ToInt32
as it will fail if the string contains invalid characgters. Use
Int32.TryParse Method (System) | Microsoft Docs[
^] so you can catch errors.
And never write
catch
{
}
that is just a waste of typing. The whole reason for using
try/catch
is to capture problems in your code and take action to either resolve them (if possible) or report them to the user.