The exception that is generated when MySQL returns an error.
The following example generates a
MySqlException due to a non-existing table, and then displays the exception.
public void ThrowMySqlException()
{
string mySelectQuery = "SELECT * FROM NONEXISTINGTABLE";
MySqlConnection myConnection =
new MySqlConnection(
"User Id=root;Host=localhost;Database=Test;");
MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (MySqlException myException)
{
MessageBox.Show("Message: " + myException.Message + "\n");
}
}
Public Sub ThrowMySqlException()
Dim mySelectQuery As String = "SELECT * FROM NONEXISTINGTABLE"
Dim myConnection As New MySqlConnection( _
"User Id=root;Host=localhost;Database=Test;")
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
Try
myCommand.Connection.Open()
Catch myException As MySqlException
MessageBox.Show("Message: " + myException.Message + ControlChars.Cr)
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2