rafaelrgl
asked on
SEE IF IS THERE SAME FIELD IN SQL DATABASE
I´M TRYING TO INSERT ROW IN MY DATABASE, FIELDS LIKE NAME AND USER CAN NOT EXIST SAME VALUES FOR THIS FIELD. IF EXIST, MY APPLICATION HAVE TO SHOW MESSAGE TO USER LIKE: "YOU HAVE TO CHANGE YOU USER NAME".
HOW CAN I DO THAT.
HOW CAN I DO THAT.
ASKER
WHERE CAN I DO THAT
add the constrain to the database or trap the exception?
ASKER
MY FIELDS ON TB_USER IS
ID
USER
NAME
HOW IS GOING TO BE MY CONTRAINT EXPRESSION FOR DO THAT.
ID
USER
NAME
HOW IS GOING TO BE MY CONTRAINT EXPRESSION FOR DO THAT.
ASKER
YOUR NAME CAME FROM BRASIL.
ASKER
THANKS
I DID, BUT RIGHT NOW, I DON´T KNOW HOW CAN I TRAP THE EXCEPTION.
CAN YOU SHOW ME.
I DID, BUT RIGHT NOW, I DON´T KNOW HOW CAN I TRAP THE EXCEPTION.
CAN YOU SHOW ME.
Hi Rafael,
I am brazilian. And I'm assuming you are too, but I will not switch to english, in case anyone else has the same problem as you
try
InsertInTable;
except on E:EDataBaseError do
end;
where InsertInTable is your method to insert in the table.
Daniela
I am brazilian. And I'm assuming you are too, but I will not switch to english, in case anyone else has the same problem as you
try
InsertInTable;
except on E:EDataBaseError do
end;
where InsertInTable is your method to insert in the table.
Daniela
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
alter TABLE test ADD CONSTRAINT uqName UNIQUE (Name)
alter TABLE test ADD CONSTRAINT uqUser UNIQUE (User)
Than, just trap the exception