sppaladugu
New member
- Joined
- Jan 29, 2007
- Messages
- 2
- Programming Experience
- Beginner
hi,
i am tring to add a new datarow to a table using the insert query, but for some reason its not working..(No exceptions thrown...) it is showing the effected rows in the database as '1' but nothing is added to the database.....if i use a select query all works fine so i guess nothing wrong with the connection.... what i am i doing wrong?????? .......
Dim DatabaseConnection As New SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Sample.mdf;Integrated Security=True;User Instance=True")
Dim DatabaseCommand As New SqlCommand
Dim InsertQuery As String
Dim DatabaseTransaction As SqlTransaction
InsertQuery = "insert into test values('shshd')"
DatabaseCommand.CommandTimeout = 60
DatabaseCommand.Connection = DatabaseConnection
DatabaseCommand.CommandType = CommandType.Text
Try
DatabaseConnection.Open()
DatabaseTransaction = DatabaseConnection.BeginTransaction()
DatabaseCommand.Transaction = DatabaseTransaction
DatabaseCommand.CommandText = InsertQuery
MsgBox(DatabaseCommand.ExecuteNonQuery())
DatabaseTransaction.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If DatabaseConnection.State <> ConnectionState.Closed Then
DatabaseConnection.Close()
End If
End Try
thanks a lot for your help in advance
i am tring to add a new datarow to a table using the insert query, but for some reason its not working..(No exceptions thrown...) it is showing the effected rows in the database as '1' but nothing is added to the database.....if i use a select query all works fine so i guess nothing wrong with the connection.... what i am i doing wrong?????? .......
Dim DatabaseConnection As New SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Sample.mdf;Integrated Security=True;User Instance=True")
Dim DatabaseCommand As New SqlCommand
Dim InsertQuery As String
Dim DatabaseTransaction As SqlTransaction
InsertQuery = "insert into test values('shshd')"
DatabaseCommand.CommandTimeout = 60
DatabaseCommand.Connection = DatabaseConnection
DatabaseCommand.CommandType = CommandType.Text
Try
DatabaseConnection.Open()
DatabaseTransaction = DatabaseConnection.BeginTransaction()
DatabaseCommand.Transaction = DatabaseTransaction
DatabaseCommand.CommandText = InsertQuery
MsgBox(DatabaseCommand.ExecuteNonQuery())
DatabaseTransaction.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If DatabaseConnection.State <> ConnectionState.Closed Then
DatabaseConnection.Close()
End If
End Try
thanks a lot for your help in advance