问题求救ACCESS数据库(50分)

D

dql_77

Unregistered / Unconfirmed
GUEST, unregistred user!
1,请问各位大虾用代码如何限制ACCESS数据库的插入记录,例如:我有数据库USER,
我想把该数据库限制只能插入20条记录,如果超出以提示方式告之.
2,请问如何把EDIT1的字符串变成日期,例如:在EDIT1中写入2002/2/2或2002-2-2,EDIT2就得到
2002年2月2日,如在EDIT1中的字符串不是日期这两种格式(2002/2/2或2002-2-2),提示告之.
谢谢各位大虾帮忙帮我解决这两个问题,小弟一定把分奉上
 
1、判断table.recount
2、用maskedit可以限制用户输入格式
字符转日期函数:strtodate('字符内容')
 
1 if RecordCount>=20 then MessageBox()
2 设定只允许几种分隔符如 “-”,“/”,“.”
if Pos('-',EDIT1.Text)>0 then
begin
DateSeparator:='-';
ShortDateFormat:='YYYY-MM-DD';
Try
Edit1.Text:=FormatDateTime('YYYY年MM月DD日',StrtoDate(Edit1.Text));
Except
.....
end;
end;
 
1.if Table1.recordcount>=20 then showmessage();
2 Edit2.Text:=FormatDateTime('YYYY''年''MM''月''DD''日',StrtoDate(Edit1.Text));
同樣道理:
Edit2.Text:=FormatDateTime('YYYY''-''MM''-''DD''-',StrtoDate(Edit1.Text));
Edit2.Text:=FormatDateTime('YYYY''/''MM''/''DD''/',StrtoDate(Edit1.Text));
 
1.
with query do
begin
close;
sql.clear;
sql.add('select * from user');
open;
end;
if query.recordcount>20 then
begin
showmessage();
exit;
end;
2.同意楼上delphiland
 
1.同意上面解决
2.只要用datetostr()来转换,只要设置异常处理就可提示用户,这样代码比较清晰
 
1、with adoQuery1 do
begin
close;
sql.Text :='select count(*) from user';
Open;
if Fields[0].asInteger >20 then ShowMessage();
end;
不可以用 RecordCount 来实现,因为有时 RecordCount 会等于 -1; Why?
2、function getInputDate(s: string): TDateTime;
var
oldDateSeparator: char;
begin
oldDateSeparator:=DateSeparator;
try
DateSeparator:='-';
if if pos('/', s) >0 then DateSeparator :='/';
try
Result :=strToDate(s);
except
raise;
end;
finally
DateSeparator:=oldDateSeparator;
end;
end;
 
顶部