I'm trying to return the largest ID of the Budget table in a variable, however it returns me an error:
An unhandled exception of type 'System.NullReferenceException' occurred in MySql.Data.dll. Additional information: object not set to an instance of an object. "
Does anyone know what it can be?
Follow the code:
public void ultimoID(int ultimoid)
{
int resultado;
var conn = new MySqlConnection(stringCon);
var sql = "SELECT MAX(id_orcamento)FROM orcamento";
var cmd = new MySqlCommand(sql, conn);
Object retorno = cmd.ExecuteScalar();
resultado = Convert.ToInt32(retorno);
}