The error message indicates that the primary key constraint on the ppatalukmaster
table is being violated. This means that the combination of values being inserted into the primary key columns already exists in the table. In this case, the duplicate key value is (3, 3).
To solve this error, you need to ensure that the combination of values being inserted into the primary key columns is unique. One way to achieve this is by checking if the combination already exists in the table before performing the insert operation.
// Check if the combination of values already exists in the table
bool combinationExists = CheckCombinationExists(model.talukcode, model.regioncode);
if (!combinationExists)
{
// Perform the insert operation
InsertData(model);
}
else
{
// Handle the duplicate key error
Console.WriteLine("Error: Duplicate key value");
}
In the above code, the CheckCombinationExists
method checks if the combination of talukcode
and regioncode
already exists in the table. If it does not exist, the InsertData
method is called to perform the insert operation. Otherwise, an appropriate error message or handling logic can be implemented.
By implementing this check, you can prevent the violation of the primary key constraint and avoid inserting duplicate values into the table.