Validation for data duplication of XML in SQL and C# asp

Occasional Visitor

I have an ASP.NET page written in C#, which has an upload button to upload a XML file. I can choose the XML file and display in grid view, which is working fine, and whenever I upload a file which has been already uploaded, it rejects the xml file with duplicate records validation.

I created a stored procedure which inserts the XML data into a temp table and then checks in the main table if the same data already exsits in the main table, and if so, it will delete those bits of data.

I need a validation message showing the there are duplicate data. How do I do it?

This is my stored procedure:

CREATE PROCEDURE [dbo].[insertDetails]        
    @xml XML, 
    @config_id varchar(100)       
        ID int IDENTITY,  
        [group] varchar(50),  
        [key]   varchar(50),  
        [label] varchar(50)  
    SET NOCOUNT ON;        

    INSERT INTO #XMLConfig        
            Configuration.value('(Group/text())[1]','VARCHAR(max)') AS [group],        
            Configuration.value('(Key/text())[1]','VARCHAR(max)') AS [key],          
            Configuration.value('(Label/text())[1]','VARCHAR(max)') AS [label]    
            @xml.nodes('/MerchantCageSettings/Configuration') AS  TEMPTABLE(Configuration)  
    DELETE #XMLConfig  
    FROM #XMLConfig xc 
    INNER JOIN xmlDataconfig gp ON xc.[group] = gp.[group] 
                                AND xc.[key] = gp.[key] 
                                AND xc.[label] = gp.[label]   
    INSERT INTO xmlDataconfig  
        SELECT * 
        FROM #XMLConfig   

In other stored procedures, I use

RAISERROR('Duplicated data',16,1);      

How do I add it or what condition should I use exactly?

0 Replies