关于数据库表格存入数据的小问题!

tangyulong520 2008-09-12 04:21:49
我想把ComboBox1里输入的内容存到数据表Comp_Pipe_Name的Pipe_Name字段中,存之前想判断一个数据库表里是否里已经存过这个记录,如 没存过再存入,判断过程我是在ComboBox1的OnExit事件中触发这个事件:代码如下:
procedure TInputDlg.ComboBox1Exit(Sender: TObject);
begin
with DataModule1.ADOquery1 do
begin
close;
sql.clear;
sql.add('select * from Comp_Pipe_Name where field =:Pipe_Name');
parameters.ParamByName('Pipe_Name').value:=combobox1.text;
open;
end;
if DataModule1.ADOquery1.recordcount>0 then
begin
Application.messagebox('已经输入过此数据','提示',0+mb_iconquestion) ;
combobox1.setfocus;
combobox1.text:='';
end;
end;
----------------------------------------------------------------------------------------
下面我想在主程序里调用这个函数(祝程序就是用来往数据库的表里存数据的),主程序是这样的:
begin
if InputDlg.ShowModal = mrok then
begin
Close;
SQL.Clear;
with DataModule1.ADOQuery1 do
begin
if not TInputDlg.ComboBox1Exit(string,Tobject) then-------------我感觉引用这好像不太对
SQL.Add('Insert Comp_Pipe_Name(Pipe_Name) Values(:a)');
Parameters.ParamByName('a').value:= InputDlg.ComboBox1.Text;
ExecSQL;
end;
end;
end;
-----------------------------------------------------------
结果编译不过去啊,[Error] digitizer_input.pas(69): Declaration expected but end of file found
请问高手是哪里的毛病呢,调用的不对,还是有逻辑错误。
...全文
135 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nongen 2008-09-13
  • 打赏
  • 举报
回复
Result是function的返回定义。
function TInputDlg.ValidCheck: boolean;

在这个函数中,result:=true跟:validcheck:=true是一样的。
-------------
tangyulong520 2008-09-13
  • 打赏
  • 举报
回复
您好,我把result定义后这个错误就消失了,但是出现了别的错误,就是在主程序里调用函数哪里:代码是倒数第七行:
if InputDlg.ValidCheck then
错误总是说:[Error] digitizer_main.pas(295): Not enough actual parameters;
并且倒数第10行说:[Error] digitizer_main.pas(292): Undeclared identifier: 'SQL';怎么会没定义呢
希望高手帮解答下

hdc733 2008-09-12
  • 打赏
  • 举报
回复
帮你顶,因为我也想学习一下.
tangyulong520 2008-09-12
  • 打赏
  • 举报
回复
有哪位高人帮着看看呗!
tangyulong520 2008-09-12
  • 打赏
  • 举报
回复
谢谢您!请教个问题,你加了2句Result := True; Result := False;是什么意思呢?
我先加了Result := True,运行提示:[Error] digitizer_input.pas(40): Undeclared identifier: 'Result',请问'Result'怎么定义呢?
当我不加Result := True时,运行提示:[Error] digitizer_main.pas(292): Undeclared identifier: 'SQL',SQL怎么会没定义呢?
谢谢!!!!!!!
simonhehe 2008-09-12
  • 打赏
  • 举报
回复


function TInputDlg.ValidCheck: boolean;
begin
Result := True;
with DataModule1.ADOquery1 do
begin
close;
sql.clear;
sql.add('select * from Comp_Pipe_Name where field =:Pipe_Name');
parameters.ParamByName('Pipe_Name').value:=combobox1.text;
open;
end;
if DataModule1.ADOquery1.recordcount>0 then
begin
Application.messagebox('已经输入过此数据','提示',0+mb_iconquestion) ;
combobox1.setfocus;
combobox1.text:='';
Result := False;
end;
end;
////////////////////////////////////////////
begin
if InputDlg.ShowModal = mrok then
begin
Close;
SQL.Clear;
with DataModule1.ADOQuery1 do
begin
if InputDlg.ValidCheck then
SQL.Add('Insert Comp_Pipe_Name(Pipe_Name) Values(:a)');
Parameters.ParamByName('a').value:= InputDlg.ComboBox1.Text;
ExecSQL;
end;
end;
end;

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧