如果一對(duì)多關(guān)系的表,用了“自動(dòng)編號(hào)”連接,就會(huì)備份后不能還原,因?yàn)椤白詣?dòng)編號(hào)”不能寫入。
可以用辦法代替“自動(dòng)編號(hào)”,也能實(shí)現(xiàn)“自動(dòng)編號(hào)”的功能。下面辦法是“Lwwvb”版主發(fā)明的,我把它改進(jìn)了。
支持多用戶同時(shí)使用,不會(huì)沖突,不會(huì)重復(fù)編號(hào)。可以完全代替“自動(dòng)編號(hào)”
1;做一個(gè)表,只有一行,放個(gè) Int 類型的字段“ID”,初值為“0”用來(lái)放參考編號(hào),
2;做一個(gè)“更新查詢”更新這個(gè)“ID”,使每次執(zhí)行“[ID] + 1”作為“自動(dòng)編號(hào)”用。
3;在窗體的“插入前”寫事件,先執(zhí)行“更新查詢”,然后取得這個(gè)“ID”值放在窗體“ID”控件的“默認(rèn)值”里面。再在“插入后”事件清除“默認(rèn)值”。
注意:要有控件綁定“ID”,控件才有“默認(rèn)值”,窗體的字段沒(méi)有“默認(rèn)值”,數(shù)據(jù)表可以使用隱藏列。
[此貼子已經(jīng)被作者于2004-12-17 13:26:14編輯過(guò)]
|