Bill, while I agree that InfoMessage could be used to pass info back,
wouldn't try catch still be needed?
Running the code below generates this output when "alter table customerss
add column gender (c)" (note the extra S).
InfoMessage and State don't provide any info when the error occurs, only the
Exception is generated.
System.Data.StateChangeEventArgs Closed Open
A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.dll
ERROR: Incorrect syntax near the keyword 'column'.
System.Data.StateChangeEventArgs Open Closed
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Using conn As New
SqlClient.SqlConnection("server=(local);database=northwind;Integrated
Security=SSPI")
AddHandler conn.InfoMessage, AddressOf conn_InfoMessage
AddHandler conn.StateChange, AddressOf conn_StateChange
Try
conn.Open()
Dim cmd As New SqlClient.SqlCommand(TextBox1.Text, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
Trace.WriteLine("ERROR: " & ex.Message)
Finally
conn.Close()
RemoveHandler conn.InfoMessage, AddressOf conn_InfoMessage
RemoveHandler conn.StateChange, AddressOf conn_StateChange
End Try
End Using
End Sub
Private Sub conn_InfoMessage(ByVal sender As Object, ByVal e As
System.Data.SqlClient.SqlInfoMessageEventArgs)
Trace.WriteLine(e.Message)
End Sub
Private Sub conn_StateChange(ByVal sender As Object, ByVal e As
System.Data.StateChangeEventArgs)
Trace.WriteLine(String.Format("{0} {1} {2} ", e.ToString,
e.OriginalState.ToString, e.CurrentState.ToString))
End Sub
End Class
"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:e5Y$(E-Mail Removed)...
> You can also pass back information about the success or failure of any
> server-side executable via the InfoMessage event. This returns low-sev
> RAISERROR and PRINT messages. You can also set OUTPUT parameters in stored
> procedures to return anything you choose. These can be inspected post
> execution.
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> INETA Speaker
> www.betav.com/blog/billva
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> __________________________________
>
> "ad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I use the codes below;
>> SqlCommand myCommand = new SqlCommand(sSql, cnn);
>> cnn.Open();
>> myCommand.ExecuteNonQuery();
>>
>> How to determinate if ExecuteNonQuery sucessful?
>>
>>
>
>