Problem: Insert one single record in a access DB using DB

From: appiez_at_bierquick.nl ((appiez_at_bierquick.nl))
Date: 06/23/04


Date: Wed, 23 Jun 2004 03:25:36 -0700

Hi all,

I encounter a strange problem wich follows me for a while now. Recently I developed a website in asp.net wich usses a 2002 access DB. At one point the user submits his entries and I insert them in the Database. Here comes the problem: Sometimes Access or ADO inserts MULTIPLE records (with the same value's) instead of just ONE!!

here is my insert code:

Public Function savePrediction(ByRef value As Prediction, ByVal cn As OleDb.OleDbConnection) As Boolean
        Try
            Const sqlString As String = "INSERT INTO Predictions (MatchId, UserId, HomePrediction, AwayPrediction) VALUES " & _
                                        "(@MatchId, @UserId, @HomePrediction, @AwayPrediction)"
            Dim myCommand As New OleDb.OleDbCommand(sqlString, cn)

            myCommand.Parameters.Add(New OleDb.OleDbParameter("@MatchId", value.MatchId))
            myCommand.Parameters.Add(New OleDb.OleDbParameter("@UserId", value.UserId))
            myCommand.Parameters.Add(New OleDb.OleDbParameter("@HomePrediction", value.HomePrediction))
            myCommand.Parameters.Add(New OleDb.OleDbParameter("@AwayPrediction", value.AwayPrediction))

            cn.Open()
            myCommand.ExecuteNonQuery()
            cn.Close()

            myCommand.Dispose()

            Return True
        Catch
            Return False
        End Try
    End Function

No wierd insert command in my opinion. Anybody an idea of what might be the problem?

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...



Relevant Pages

  • Re: Function call
    ... I think Stephan and I are on the same track -- passing a name instead of a form object. ... If I use the code above from a command button's Click event, I end up needing to use error handling on every form that has a Close button, rather than using error handling just once in the public function. ... Dim strForm As String ...
    (microsoft.public.access.formscoding)
  • Re: Function call
    ... Click event line on a command button's property sheet, all I need to do is ... Public Function CloseForm(frmName as string) ... Public Function DeptForm() ... Dim strForm As String ...
    (microsoft.public.access.formscoding)
  • Re: Generics - type casting
    ... Public Function GetDataSet(ByVal command As SqlCommand) As DataSet ... By examining the generics argument, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Write to stdout
    ... I tried this code for a command line app, ... > Public Function ConsoleWriteLine(sText As String) As Long ...
    (microsoft.public.vb.general.discussion)
  • NOT USING RECORDSETS - "Transaction cannot have multiple recordsets with this cursor type. Chan
    ... i am having problems with the above error when using the command ... > Private Function AddAs Boolean ... > Public Function Execute(ByRef cmd As ADODB.Command, ...
    (microsoft.public.data.ado)