Multiple Primary Key Update

Posts   
 
    
Posts: 27
Joined: 23-Mar-2012
# Posted on: 25-Apr-2012 13:53:08   

Hi all,

In a table i have a pair of primary key and when i tried to update record, exception is thrown

An exception was caught during the execution of an action query: Duplicate entry '5S-3880586-12331-KFL-850 ' for key 'PRIMARY'.

objDetailServisSpareSpart.IsNew = false;
                            objDetailServisSpareSpart.No = txtNo.Text;
                            objDetailServisSpareSpart.SparePartCode = gridLookUpSparePart.EditValue.ToString();
                             objDetailServisSpareSpart.Qty = objDetailServisSpareSpart.Qty +
                                                                   (int) txtQty.EditValue;
                            objDetailServisSpareSpart.Save();

The primary key are objDetailServisSpareSpart.No and objDetailServisSpareSpart.SparePartCode

I'm trying to change the qty

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 25-Apr-2012 16:35:22   

Check the SQL query that's being produced (enable tracing, see 'troubleshooting and debugging' in the docs)

please next time post in the right forum, thanks.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 27
Joined: 23-Mar-2012
# Posted on: 25-Apr-2012 17:22:15   

Sorry for post in wrong forum.

Check the SQL query that's being produced (enable tracing, see 'troubleshooting and debugging' in the docs)

I tried to read the docs but i didn't understand. I usually debug in VS.NET using standart debugging.

The only SQL Query i found on debugging is :

"\r\n\tQuery: UPDATE `detailservissukucadang` SET `JumlahSukuCadang`=@p1 WHERE ( ( `detailservissukucadang`.`KodeSukuCadang` = @p2 AND `detailservissukucadang`.`NomorNota` = @p3))\r\n\tParameter: @p1 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 2.\r\n\tParameter: @p2 : AnsiString. Length: 30. Precision: 0. Scale: 0. Direction: Input. Value: \"12331-KFL-850 \".\r\n\tParameter: @p3 : AnsiString. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: \"5S-3880586\".\r\n"
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2012 20:14:00   

As Otis said, please check "Troubleshooting & Debugging" in the docs. There you should know how to enable DQE tracing output. Then when debugging you should find the queries in the output window of VS.

Posts: 27
Joined: 23-Mar-2012
# Posted on: 26-Apr-2012 17:24:27   

Thanks Walaa for the reply.

I Think i know the problem.

Let me ask a new question : How to know whether the record was on the table or not?

I once used other ORM and it goes like this :

classItem objItem = new classItem();
objItem.Code = "A123";
objItem.Seek();

If (objItem.Rows > 0)
    //The Data was there
Else
    //The Data wasn't there

How about LLBLGEN ?
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Apr-2012 19:29:05   

You will have to query the table for that record. Either by selecting a field, or by doing Count(). And anyway you'll have to filter on the PK.

You can also attempt to fetch the entity. Selfservicing: by creating a new instance passing the PK. Adapter: by using FetchNewEntity().

Posts: 27
Joined: 23-Mar-2012
# Posted on: 29-Apr-2012 08:30:42   

The solution to my question about multiple primary key update is to backup the database, drop it and then rebuild it with backup file.

Anyway, thanks for the help