Validate repeated identifiers with C #

1

I'm doing a chat with ASP .NET SQLServer. I want to validate to show the comment "hello greeting 1" once and then down their respective answers. The next image of the problem.

    
asked by Arnaldo 13.02.2017 в 21:49
source

2 answers

2

Your database seems to be not normalized, but you can still do what you want.

SQL The easiest way is from the SQL query, first get the comment and then your answers:

SELECT distinct IdComentario, Comentario FROM <tu tabla>
SELECT respuesta FROM <tu tabla> WHERE IdComentario = < x >

C # Use a DataTable and one of its sorting methods.

Preferably normalizes your database, that is, a "Comments" table and a "Responses" dependent table.

    
answered by 13.02.2017 в 22:10
0

I'm not sure of the structure of your database, but I'm confused as to why you have the duplicate comment id, I would add a column to identify which chat you are referring to and would execute this when you want to insert a new comment:

IF EXISTS (select Comentarion from Table
WHERE Comentario=@comentario AND IdChat = @Chat)
 BEGIN
    PRINT 'No insertar'
 END
 ELSE
 BEGIN
    INSERT INTO .....
END

This can be in trigger or call it in Stored Procedure

    
answered by 13.02.2017 в 22:07