For some reason my stored procedures are all executing twice! I have a static function that runs an SP given its name and the parameters and fills a datatable.
Public Shared Function RunSP(ByVal spName As String, ByRef spParams As Dictionary(Of String, String), ByRef pDataTable As DataTable) As Integer
Dim cmd As New SqlCommand
Dim lAdapter As SqlDataAdapter
Try
cmd.Connection = New SqlConnection(ConnectionString)
cmd.Connection.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = spName
For Each item As KeyValuePair(Of String, String) In spParams
cmd.Parameters.AddWithValue(item.Key, item.Value)
Next
cmd.ExecuteNonQuery()
If Not pDataTable Is Nothing Then
lAdapter = New SqlDataAdapter(cmd)
lAdapter.Fill(pDataTable)
End If
RunSP = 0
Catch ex As Exception
If (Not cmd Is Nothing) Then
cmd.Dispose()
End If
RunSP = -1
End Try
End Function
Is there something wrong with the code? I've checked with the debugger and the appropriate SPs are definitely only being called once, i.e. this function only runs once for a particular insertion function, but two things are inserted into the table.