[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

ODBC return codes from .Net ODBC provider

Steve

5/16/2002 9:59:00 PM

If I am using ExecuteNonQuery and an error occurs I get a
system error exception thrown.How can I tell what that
error is - I need to know for example that the unique key
already exists or a referential integrity check has failed.
2 Answers

(Hussein Abuthuraya(MSFT))

5/17/2002 1:28:00 AM

0

Steve

5/17/2002 12:57:00 PM

0

Thanks for your help, that should be fine. I'd used
try/catch but didn't bother reading up on the exception
classes. That should take care of the next couple of
weeks !

Christ, who needs a life anyway.


>-----Original Message-----
>Steve,
>
>Wrap the ExecutNonQuery call in a try catch block as
follows:
>
> Try
> cmd.ExecuteNonQuery()
> Catch myException As OdbcException
> Dim i As Integer
> For i = 0 To myException.Errors.Count - 1
> MessageBox.Show("Index #" + i.ToString() +
ControlChars.Cr _
> + "Message: " + myException.Errors
(i).Message + ControlChars.Cr _
> + "Native: " + myException.Errors
(i).NativeError.ToString() + ControlChars.Cr _
> + "Source: " + myException.Errors
(i).Source + ControlChars.Cr _
> + "SQL: " + myException.Errors(i).SQLState
+ ControlChars.Cr)
> Next i
> Finally
> cn.Close()
> End Try
>
>The messagebox will display the exception details. Try
to recreate the errors and then get the Native number.
Then add If statemtns to check for that particular number
and
>then do whatever you like accordingly.
>
>I hope this helps!
>
>
>Thanks,
>Hussein Abuthuraya
>Microsoft Developer Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>
>Are you secure? For information about the Microsoft
Strategic Technology Protection Program and to order your
FREE Security Tool Kit, please visit
>http://www.microsoft.co....
>