1 (edited by v_pozidis 2020-04-29 10:18:58)

Topic: Pls !! How to avoid double record when adding direct in tablegrid

How can I avoid double record when adding direct in tablegrid

Re: Pls !! How to avoid double record when adding direct in tablegrid

Can please somebody help me. It's urgent.

Re: Pls !! How to avoid double record when adding direct in tablegrid

Are you needing to check just one cell/ column in the grid or the complete row for duplicates?

On a clear disk you can seek forever

Re: Pls !! How to avoid double record when adding direct in tablegrid

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.

5 (edited by CDB 2020-04-29 22:24:04)

Re: Pls !! How to avoid double record when adding direct in tablegrid

OK, I had written an answer and then clicked the back button on my browser and lost it! sad

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.

On a clear disk you can seek forever

6 (edited by CDB 2020-04-29 23:05:49)

Re: Pls !! How to avoid double record when adding direct in tablegrid

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 .

On a clear disk you can seek forever

7 (edited by derek 2020-04-30 00:18:22)

Re: Pls !! How to avoid double record when adding direct in tablegrid

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.

Post's attachments

Attachment icon editable tablegrid inserts.zip 336.59 kb, 322 downloads since 2020-04-30 

Re: Pls !! How to avoid double record when adding direct in tablegrid

Thank you all,
Derek this was exactly what i was looking for.

9 (edited by v_pozidis 2020-05-05 10:28:30)

Re: Pls !! How to avoid double record when adding direct in tablegrid

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

Post's attachments

Attachment icon editable tablegrid insert(1).7z 274.43 kb, 261 downloads since 2020-05-05 

Re: Pls !! How to avoid double record when adding direct in tablegrid

When inserting direct to the tablerid two records with relationship is there a case to avoid double records?