建议另加一ADOQuery进行判断
datamodule1.ADOQ_query.
procedure TF_main.suiButton15Click(Sender: TObject);
begin
with datamodule1.ADOQ_query. do
begin
close;
SQL.Clear;
SQL.Add('select * from 学生表 where 学号=:xh');
parabyname('xh'):= trim(dbedit1.text);
open;
if recordcount>0 then
begin
smd1.Caption := '系统提示';
smd1.Text:= '您输入的"学号"在系统中已经存在,请重新输入!';
smd1.ShowModal;
dbedit1.SetFocus ;
exit;
end;
datamodule1.adoq_xs.post;
end;
这样不会影响你向数据库写入东西;
你是如果不存在就添加吧?
这样啊
query1.sql := 'insert ....................................';
try
query1.execsql ;
except on exception do
if exception.message=reason1 then
else if exception.message=reason2 then
else
procedure TF_main.suiButton15Click(Sender: TObject);
begin
with datamodule1.ADOQ_xs do //用Query 组件要设置 DatabaseName 属性
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM 学生表 WHERE 学号='+QuotedStr('dbedit.text'));
Open;
if not IsEmpty then
ShowMessage('已存在');
end;
end;
请问帮我改一下!!谢谢了!!
with Table1 do //用Table 组件要设置 DatabaseName 和 TableName 属性
begin
Open;
Filter:='学号='+QuotedStr('ABC0001');
if FindFirst then
ShowMessage('已存在');
end;
with Query1 do //用Query 组件要设置 DatabaseName 属性
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM tablename WHERE 学号='+QuotedStr('ABC0001'));
Open;
if not IsEmpty then
ShowMessage('已存在');
//也可以这样:
Close;
SQL.Clear;
SQL.Add('SELECT * FROM tableName');
Open;
Filter:='学号='+QuotedStr('ABC0001');
if FindFirst then
ShowMessage('已存在');
end;