A Function To Simplify ExecuteNonQuery Statements

Use this function to simplify ExecuteNonQuery. Normally, you need to setup a command and connection objects, which this code does. Just pass the SQL statement and the connection object that points to your database.

Function ExecuteSQL(ByVal sSQL As String, ByVal dbOLE As OleDb.OleDbConnection) As Integer
Dim command As New OleDb.OleDbCommand(sSQL, dbOLE)
If command.Connection.State = ConnectionState.Closed Then command.Connection.Open()
Command.CommandType = CommandType.Text
ExecuteSQL = command.ExecuteNonQuery()
command.Connection.Close()
Application.DoEvents()
End Function

0 comments:

Post a Comment