久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

“違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'

quot;Violation of PRIMARY KEY constraint #39;PK_Vehicle_Transactions#39;. Cannot insert duplicate key in object #39;dbo.Vehicle_Transactionsquot;(“違反 PRIMARY KEY 約束 PK_Vehicle_Transactions.無法在對象“dbo.Vehicle_Transactions中
本文介紹了“違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'.無法在對象“dbo.Vehicle_Transactions"中插入重復鍵的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我設計了 Webservice api,每次我通過 Webservice 推送數據時,這就是我得到的回報MOV = "違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'.無法在對象 'dbo.Vehicle_Transactions' 中插入重復鍵.語句已終止."就像 api 不知道它在哪里停止以及在哪里繼續!請在下面查看我的源代碼,謝謝

There's Webservice api that I design, Each time I push data cross the webservice this is what I get in return MOV = "Violation of PRIMARY KEY constraint 'PK_Vehicle_Transactions'. Cannot insert duplicate key in object 'dbo.Vehicle_Transactions'. The statement has been terminated." is like the api doesn't know where it stopped and where to continue! kindly see my source code below thanks

Public Sub uploadVehicle_Transaction()
        Try
            'do for sync indacator for proper upload in action
            Dim VT As New DataTable
            VT = New Statn_Sync.DataSetTableAdapters.Vehicle_TransactionsTableAdapter().GetData()

        For Each dr As DataRow In VT.Rows
            Dim iCount As Integer = 0
            Dim MOV As String = comT.insertVehicle_Transaction(Convert.ToInt64(dr("TransactionID")), _
                                                               Convert.ToDateTime(dr("Transaction_date")), _
                                                               Convert.ToInt32(dr("Bank")), _
                                                               Convert.ToString(dr("Teller_number")), _
                                                               Convert.ToInt32(dr("Amount")), _
                                                               Convert.ToString(dr("Generated_by")), _
                                                               Convert.ToString(dr("Station")), _
                                                               Convert.ToString(dr("Customer_name")), _
                                                               Convert.ToInt32(dr("Transaction_category")), _
                                                               Convert.ToString(dr("Deposit_slip")), _
                                                               Convert.ToInt32(dr("Sync")), _
                                                               Convert.ToDecimal(dr("Penalty")), _
                                                               Convert.ToDecimal(dr("OGSG")), _
                                                               Convert.ToDecimal(dr("CMR")), _
                                                               Convert.ToDecimal(dr("Goshen")), _
                                                               Convert.ToDecimal(dr("Insurance")), _
                                                               Convert.ToDecimal(dr("OCost")), _
                                                               Convert.ToDecimal(dr("OGSG_Renewal")), _
                                                               Convert.ToDecimal(dr("De_pulse")))

            iCount += 1
            Label1.Text = " Auto Sync: " & iCount
            'update record
            Dim pls As String = dr("TransactionID").ToString

            If (pls Is MOV) Then
                AddToLog((Convert.ToString(": transferred") & MOV.ToString() & Text) + Environment.NewLine)
                vta.UpdateTrans(dr("TransactionID"))
            End If
        Next

    Catch ex As Exception
        AddToLog(ex.Message.ToString)
    End Try
End Sub

推薦答案

異常已經說明了:違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'.表中已經包含一行,其中給出了主鍵 (TransactionID).主鍵在整個表中是唯一的.

The exception already says it: Violation of PRIMARY KEY constraint 'PK_Vehicle_Transactions'. The table already contains a row with the Primary Key (TransactionID) given. A Primary Key is unique throughout the table.

您的問題有多種解決方案:

There are several solutions for your problem:

1) 計算最新的TransactionID

VT = New Statn_Sync.DataSetTableAdapters.Vehicle_TransactionsTableAdapter().GetData()

//Use query to select Max value of TransactionID (something like)
Dim maxPK as Long =  'SELECT MAX(TransactionID) FROM dbo.Vehicle_Transactions'  

//Increase the MaxPK with 1 to avoid duplicate key
 maxPK = maxPK + 1 

  For Each dr As DataRow In VT.Rows
   Dim iCount As Integer = 0

   //Use our variable in the insert
   Dim MOV As String = comT.insertVehicle_Transaction((maxPK  + iCount), _
                       Convert.ToDateTime(dr("Transaction_date")), _

2) 在 dbo.Vehicle_Transactions

為此,我參考以下帖子:Auto Increment.這篇文章是為MSSQL 2012的管理工作室做的.但同樣的邏輯適用于早期版本(2008,2005)

For this i refer to the following post: Auto Increment .This post was made for the management studio of MSSQL 2012. But the same logic applies for earlier version (2008,2005)

可以在 StackOverflow 中找到其他解決方案

Other solutions might be found throughout StackOverflow

如果我能提供任何進一步的幫助,請不要猶豫給我簽名!

If i can be of any further assistance, don't hesitate to give me sign!

注意:如果之前的數據對你沒有用,你總是可以在插入之前清除表使用查詢:DELETE FROM dbo.Vehicle_Transactions此查詢從表中刪除所有行.盡管您必須警惕任何Forgein Keys,因為它們可能會導致數據丟失/異常.

Note: If the previous data are of no use to you, you can always clear the table prior to the insert using the query: DELETE FROM dbo.Vehicle_Transactionsthis query removes all rows from the table. Though you have to wary for any Forgein Keys as they might cause dataloss/exceptions.

這篇關于“違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'.無法在對象“dbo.Vehicle_Transactions"中插入重復鍵的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉換為其整數表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 国产高清一区二区 | 日韩在线免费观看视频 | 日本久久精品视频 | 伦理午夜电影免费观看 | 大久 | 狠狠干五月天 | www.五月天婷婷.com | 国产乱码精品一品二品 | 麻豆av在线 | 国产一区视频在线 | 亚洲人成在线观看 | 久久久久久网站 | 成年人视频在线免费观看 | 久久午夜精品 | 中文字幕一区二区三区精彩视频 | 日日夜夜精品视频 | 韩日有码 | 久草青青草 | 97人人澡人人爽91综合色 | 欧美中文字幕一区 | 亚洲免费大片 | 日韩av成人在线 | 国产欧美日韩精品一区二区三区 | 99久久婷婷国产综合精品电影 | 亚洲精品女人久久久 | 精品视频一区二区三区在线观看 | 欧美精品久久久 | 久久久久国产一区二区三区 | 精品不卡 | 91精品久久久久久久久久 | 亚洲aⅴ | 国产精品一区二区在线免费观看 | 亚洲第一在线 | 久久中文一区二区 | 亚洲欧美bt | 99在线资源 | 国产精品成人一区二区三区夜夜夜 | 日韩中文字幕一区 | 尤物在线| 欧美一二三区 | 国产精品久久久亚洲 |