How to ignore a exception
and insert the rest of the fields when I get this error in MYSQL using mysql .NET connector? My try catch
is as follows:
try
{
conexao.Open();
MySqlDataReader reader = comm.ExecuteReader();
reader.Read();
return reader.GetString("ID");
}
catch (MySqlException e)
{
if (e.Number == 1062) //Duplicate entry
{
MySqlDataReader reader = comm.ExecuteReader();
reader.Read();
return reader.GetString("ID");
}
else
{
Debug.WriteLine(Query);
Debug.WriteLine(e);
return "Error";
}
}
catch (Exception e)
{
Debug.WriteLine(Query);
Debug.WriteLine(e);
return "Error";
}
finally
{
conexao.Close(); //Fechando a conexão
}
Naturally when I have duplicate emails within the values
of my query I fall into the first catch (MySqlException e)
within it I started to filter the error by if (e.Number == 1062
it checks and falls right inside that if
, however when I go I would like to insert 99 and ignore the email that already exists in the table.