CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question Violation of primary key issue

    Can anyone tell me ???.why i am getting the following issue ???.
    Violation of PRIMARY KEY constraint 'PK_CNK_dailysales'. Cannot insert duplicate key in object 'CNK_dailysales'.
    here is the following code what i have written
    Code:
    Public Sub InsertDailySales(rs As ADODB.Recordset)
    Dim con As ADODB.Connection
    Dim tempdate As Date
    Dim strMsg$, StrMsgSales$
    Dim TotalValue#
    Dim totalQty%
    If Not OpenConnection(con) Then
       MsgBox ("Connection is not open ")
       Set con = Nothing
       Exit Sub
    End If
    On Error GoTo errhnd
    Dim TempSerial As String
    TempSerial = ""
     rs.MoveFirst
     Do While Not rs.EOF
      If TempSerial <> rs!saleserial Then
         TempSerial = rs!saleserial
        If TempSerial <> "" Then
           con.Execute "Insert into interface.dbo.CNK_dailysales(Storeid,Saleserial,SaleInternalDate,dumpdate,nettotal) values('" & rs!StoreId & "','" & rs!saleserial & "','" & Format(rs!saleinternaldate, "YYYY-MM-DD") & "','" & Format(Now(), "YYYY-MM-DD HH:MM:SS") & "','" & "0" & "')"
        End If
    End If
    rs.MoveNext
    Loop
    strMsg = strMsg & rs!StoreId & " Total Sales" & vbTab & CDbl(TotalValue) & vbTab & " Total Qty" & vbTab & CInt(totalQty) & vbNewLine
                StrMsgSales = StrMsgSales & rs!StoreId & " Total Sales" & vbTab & CDbl(TotalValue) & vbTab & " Total Qty" & vbTab & CInt(totalQty) & vbNewLine
                ' Updating the Generated Files Date time Informations
                con.Execute "Update CNK_Stores set LastSaleDate='" & Format(DateAdd("d", 1, tempdate), "YYYY-MM-DD") & "' where INF_CODE='" & rs!StoreId & "'"
    errhnd:
      Debug.Print Err.Description
    '  Err.Clear
    '  On Error GoTo 0
        
        
    End Sub
    Last edited by firoz.raj; April 6th, 2011 at 03:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured