About   -   Contact   -   Purchase   -   Search   -   What's New

Duplicate Rows Checking
This tip was submitted by Charles Ginzel.

Here is a clever datawindow trick which determines if there are duplicate rows in the datawindow before saving to the database. In the example below, the unique key in the database is "user_id", so what we are doing here is sorting them and then filtering in a way which leaves only the duplicate rows. If the row count is greater than zero after the sort, there is a problem... no looping necessary!

//now use this sort and filter to leave only duplicate rows
lds_buffer.SetSort ("user_id A")
lds_buffer.SetFilter ("user_id = user_id[-1]")

if lds_buffer.RowCount() > 0 then
	//got a dup, tell the user which one!
	al_row = lds_buffer.GetItemNumber (1, "row_num")
	as_colname = "user_id"
	as_error = "Duplicate User ID."

	return -4
end if

//no dups, so clear the filter and do the update...
lds_buffer.SetFilter ("")

Top of Page

Legal Notice

Ken Howe 2011