Solved

Creating SQL Trigger via Code

Posted on 2004-09-14
5
223 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:VBSMerlin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:RacinRan
ID: 12057206
If it's SQL Server ... send the database drop trigger and create trigger statements.

Racin


0
 
LVL 1

Author Comment

by:VBSMerlin
ID: 12057967
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
 
LVL 3

Expert Comment

by:RacinRan
ID: 12058016
Should be able to just send as a regular sql command.
0
 
LVL 1

Author Comment

by:VBSMerlin
ID: 12058076
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
 
LVL 7

Accepted Solution

by:
natloz earned 250 total points
ID: 12058312
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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question