erm man

erm man

  • NA
  • 1
  • 1.2k

Why the insert command Delete old rows in the database

May 10 2012 8:09 AM

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 ?



Answers (1)