David David - 2 months ago 6x
SQL Question

INSERT query is executing but not inserting

I have the following subroutine in my code for inserting a new record into a SQL Server database. After stepping through it, the code goes through it all, the message box appears, but the row is not actually inserted into the database. I know it's using the right connection as I can view records on the related grid that I manually inserted using SQL Server, and also my

queries work, using the same connection, so something is wrong with my code but I can't work out what... Can anybody help me?

Public Shared Function SaveNewIncident(ByVal clientName As String, dateStart As Date, dateEnd As Date, ByVal incidentProblem As String, ByVal timeStart As String, ByVal timeEnd As String,
ByVal incidentSolved As Boolean, ByVal incidentSolution As String, _con As OleDbConnection)

Dim tr As OleDbTransaction = Nothing

tr = _Con.BeginTransaction()

Dim Dc As New OleDbCommand
Dc.Connection = _con

Dim ID As Integer
ID = "1"

Dc.CommandType = CommandType.Text
Dc.CommandText = "INSERT INTO dbo.tblIncidents VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"
Dc.Transaction = tr
Dc.Parameters.Add("@supportID", OleDbType.Integer).Value = ID
Dc.Parameters.Add("@clientName", OleDbType.VarChar).Value = clientName
Dc.Parameters.Add("@dateStart", OleDbType.Date).Value = dateStart
Dc.Parameters.Add("@dateEnd", OleDbType.Date).Value = dateEnd
Dc.Parameters.Add("@incidentProblem", OleDbType.LongVarChar).Value = incidentProblem
Dc.Parameters.Add("@timeStart", OleDbType.VarChar).Value = timeStart
Dc.Parameters.Add("@timeEnd", OleDbType.VarChar).Value = timeEnd
Dc.Parameters.Add("@incidentSolved", OleDbType.Boolean).Value = incidentSolved
Dc.Parameters.Add("@incidentSolution", OleDbType.LongVarChar).Value = incidentSolution


MsgBox("Save successful")

Catch ex As Exception

mdInit.errorLog(ex.Message, ex.StackTrace)
MsgBox("Failed to save data, refer to error log")

End Try

End Function


you haven't executed your insert query. add the below code before tr.Commit()