SqlState Property (MySqlException)
Returns a string containing the SQLSTATE error code for the last error.
'Declaration
Public ReadOnly Property SqlState As String
Property Value
Error code for the last error.
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
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