I want to return the last column of most recently inserted record from a database table. I keep getting this error: 

> 
> A first chance exception of type 'System.InvalidCastException' occurred in SchoolManagement.exe
> 
> 
> Additional information: Specified cast is not valid.
> 
> 
> If there is a handler for this exception, the program may be safely continued
> 
> 
> 

Code:

```
public int A()
{
    string _connection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
    string stmt = "SELECT TOP 1 RegistrationNumber FROM tblStudentBiodata ORDER BY RegistrationNumber DESC";

    int count = 0;

    using (SqlConnection thisConnection = new SqlConnection(_connection))
    {
        using(SqlCommand cmdCount = new SqlCommand(stmt, thisConnection))
        {
            thisConnection.Open();
            count = (int)cmdCount.ExecuteScalar();
        }
    }
    return count;
}

```