久久久久久久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 推送數(shù)據(jù)時,這就是我得到的回報MOV = "違反 PRIMARY KEY 約束 'PK_Vehicle_Transactions'.無法在對象 'dbo.Vehicle_Transactions' 中插入重復鍵.語句已終止."就像 api 不知道它在哪里停止以及在哪里繼續(xù)!請在下面查看我的源代碼,謝謝

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!

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

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模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(jié) [])
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(將一天的名稱轉換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 亚洲欧美一区二区三区国产精品 | 四虎av电影 | 国产在线精品一区二区三区 | 欧美精品在线一区 | 国产精品久久久久久中文字 | www.99re| 国产一级视频在线播放 | 国产9999精品 | 婷婷色婷婷 | 欧美日韩亚洲一区二区 | 羞视频在线观看 | 在线看一区二区 | 91av视频 | 国产在线观看一区二区 | 欧美一级黄色片免费观看 | 成人深夜福利 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 | 久草免费在线视频 | 国产视频一区二区 | 美女福利视频网站 | 中国一级大毛片 | 国产精品网址 | 国产日韩久久久久69影院 | 美女视频一区二区三区 | 国产精品99久久久久久大便 | 视频一区二区三区中文字幕 | 精品国产乱码久久久久久老虎 | 青青草中文字幕 | 第四色狠狠| 国产伦精品一区二区三区照片91 | 成人深夜福利 | 少妇一区二区三区 | 成av人电影在线 | 国产精品入口久久 | 羞羞视频网站在线观看 | av手机在线免费观看 | 国产精品亚洲一区二区三区在线 | 精品欧美一区二区在线观看 | 一区二区在线看 | 香蕉视频一区二区 | 日韩久久中文字幕 |