Topic: Pls !! How to avoid double record when adding direct in tablegrid
How can I avoid double record when adding direct in tablegrid
My Visual Database → General → Pls !! How to avoid double record when adding direct in tablegrid
How can I avoid double record when adding direct in tablegrid
Can please somebody help me. It's urgent.
Are you needing to check just one cell/ column in the grid or the complete row for duplicates?
Hi, what I want is when I add direct to the tablegrid using the command allow new record or the update it should stop add , and shows a warning message. I do not want doublicates records in the whole tablegrid.
OK, I had written an answer and then clicked the back button on my browser and lost it!
I would do this:
Have an OnCellDoubleClick event on your tablegrid.
procedure Form1_tablegrid1_OnCellDoubleClick(Sender: TObject; ACol, ARow: Integer);
var
dupcheck:string;
begin
dupcheck:= Form1.tablegrid1.cell[ACol, ARow];
..//dupcheck will contain the contents of whichever cell you have clicked on.
..
..
end;
See ehwagners SQL code for duplicate checking here http://myvisualdatabase.com/forum/viewt … p?id=6219.
This means you have to double click on your cell after entering data for the check to fire, it might be eaiser to get the double click to open an entry form and then use ehwagners code.
Warning! I seem to always go for the complicated way of doing things, so the experts here may have a simpler answer.
I've had some further thoughts. Using DB Browser or SQLite studio you could make the columns you need to check for duplicates as UNIQUE the database should then complain everytime you enter a duplicate value.
This also might work in a SQL statement:
dbcheck:string;
dbcheck:=SQLExecute(SELECT * FROM your_table WHERE your_column IN (SELECT your_column FROM your_table WHERE your_column = "your duplicate value here"));
This returns duplicates
So the Pascal would be
If dupcheck = dbcheck
do something here.
An alternative on the above is to change IN to NOT IN , this would then return all records but the duplicate.
The Pascal would then change to
if dupcheck <> dbcheck .
Hello All,
Perhaps try it like this (see attached).
I'm only checking on a single field (to keep the example simple) but if there were more fields to check, you would just build on the same logic.
Regards,
Derek.
Thank you all,
Derek this was exactly what i was looking for.
hi Derek (again your help) How is this possible to add direct to the tablegrid with Relationship . Please feel free to work on my example. Thank you in advance
When inserting direct to the tablerid two records with relationship is there a case to avoid double records?
My Visual Database → General → Pls !! How to avoid double record when adding direct in tablegrid
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi