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.
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.
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