Creating SQL Trigger via Code

Does anyone know how to manage trigger via code, I'm more interested in being able to delete and create triggers from within my application (VB.Net).

VBSMerlin
LVL 1
VBSMerlinAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
natlozConnect With a Mentor Commented:
Here is a code snippet...

Dim cDB As clsDBConn = New clsDBConn 'Connection Class
        Dim strConn As String = cDB.getStrConn 'Get connection string for database
        Dim oConn As New SqlConnection 'SQL connection object
        Dim intReturnID As Integer 'Return ID from Stored Procedures
        Dim oComm As SqlCommand 'SQL Command object

        Try
            'Pass connection string to SqlConnection
            oConn.ConnectionString = strConn

            'SQL Database statements
            oComm = New SqlCommand
            oComm.CommandType = CommandType.Text
            oComm.CommandText = "drop trigger trg_test"
            oComm.Connection = oConn

            oConn.Open() 'Open connection
            oComm.ExecuteNonQuery() 'Execute SQL Statement to drop trigger
            oConn.Close() 'Close connection

        Catch ex As Exception
            MsgBox(ex.ToString)
            MsgBox("Error connecting to SQL Server")
        End Try

        'Return the ID added or ERROR Code
        Return intReturnID
0
 
RacinRanCommented:
If it's SQL Server ... send the database drop trigger and create trigger statements.

Racin


0
 
VBSMerlinAuthor Commented:
but how would i send that from code just as a regular sql command??? or is there something in the framework that can take care of that?

VBS
0
 
RacinRanCommented:
Should be able to just send as a regular sql command.
0
 
VBSMerlinAuthor Commented:
RacinRan,  I will leave this open for about 2 hours to see if i get any other comment otherwise the points are yours

VBSMerlin
0
All Courses

From novice to tech pro — start learning today.