SqlState Property (MySqlException)
In This Topic
Returns a string containing the SQLSTATE error code for the last error.
Syntax
|
|---|
'Declaration
Public ReadOnly Property SqlState As String |
Property Value
Error code for the last error.
Example
The sample shows how to retrieve error code in exception handler.
|
|---|
try
{
MySqlConnection connection = new MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test");
connection.Open();
MySqlCommand command = new MySqlCommand("insert into dept values (10,'test,'test')", connection);
command.ExecuteNonQuery();
command.ExecuteNonQuery();
}
catch (MySqlException ex)
{
Console.WriteLine("Message: " + ex.Message);
Console.WriteLine("Code: " + ex.Code.ToString());
Console.WriteLine("SqlState: " + ex.SqlState);
} |
|
|---|
Try
Dim connection As MySqlConnection = New MySqlConnection("User Id=test; Host=localhost; Port=3306; Database=test")
connection.Open()
Dim Command As MySqlCommand = New MySqlCommand("insert into dept values (10,'test,'test')", connection)
Command.ExecuteNonQuery()
Command.ExecuteNonQuery()
Catch ex As MySqlException
Console.WriteLine("Message: " + ex.Message)
Console.WriteLine("Code: " + ex.Code.ToString())
Console.WriteLine("SqlState: " + ex.SqlState)
End Try |
See Also