Execute Non Query Sql Cmd (Signature 1)
Executes a non-query SQL command (such as INSERT, UPDATE, DELETE) on the specified SqlConnection .
This function ensures that the connection is open before executing the command. It returns 0 if an exception is thrown, with no error details exposed.
VB
Public Function ExecuteNonQuerySqlCmd(MyConnection As SqlConnection,
SqlCmd As String) As Integer
Try
If Not MyConnection.State = ConnectionState.Open Then MyConnection.Open()
Dim MyCmd As New SqlCommand(SqlCmd, MyConnection)
Return MyCmd.ExecuteNonQuery()
Catch ex As Exception
Return 0
End Try
End Function