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




Reply With Quote