Reputation: 13
I'm trying to add a row in the database by using the insert
command.
It successfully adds the row, but the old rows in the database were deleted after executing the command!
Dim connetionString As String
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim sql As String
connetionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Datab1.mdf;Integrated Security=True;User Instance=True"
sql = "INSERT INTO Table1 VALUES ('e', 'e')"
cnn = New SqlConnection(connetionString)
Try
cnn.Open()
cmd = New SqlCommand(sql, cnn)
cmd.ExecuteNonQuery()
cmd.Dispose()
cnn.Close()
MsgBox(" ExecuteNonQuery in SqlCommand executed !!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
What is wrong ?
Upvotes: 0
Views: 149
Reputation: 20745
Find the trigger created on this table which is causing to delete the old rows.
If you want to quickly list down the tables having triggers in your database, here's how to do so:
USE [YourDB]
SELECT
OBJECT_NAME(parent_id) AS TableName,
name AS TriggerName,
create_date AS CreationDate,
modify_date AS ModifyDate
FROM sys.triggers
Upvotes: 1