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 |