Solved

Creating SQL Trigger via Code

Posted on 2004-09-14
5
222 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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