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

From: Val Mazur (group51a_at_hotmail.com)
Date: 06/24/04


Date: Wed, 23 Jun 2004 22:01:49 -0400

Hi,

I see only one potential problem here - do you call this function inside of
some sort of the event? If yes, then it might be that function is called
several time in a case if event, which calls it, fires several times.

-- 
Val Mazur
Microsoft MVP
"Appiez" <appiez@bierquick.nl> wrote in message 
news:emXNtxQWEHA.1368@TK2MSFTNGP10.phx.gbl...
> 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...