The error conversion from type dbnull to type integer is not valid
is thrown when you try to assign a DBnull to an integer type variable. This usually happens when the database field has no value, which is dbnull, and the value is assigned to a variable without checking. It is difficult to exactly pin point from your code. It is better to use the break point in debugging mode and step through the code to find where this error is thrown. After finding the code line then check for DBnull and assign appropriate value.
The problem could be in this statement
reg_id = cmd.ExecuteScalar
Because on execution of cmd.ExecuteScalar, if the datbase field does not have a value, it will try to assign DBNull to integer type variable,reg_id, which will result in the above error.
If your problem is solved, you may accept and vote the solution, otherwise please post your queries