请老师们帮我看一段代码!急急!!

gdczwzq 2004-05-06 04:22:15


编译的时候没有出错,一执行(只要在EDIT1中打入字符就出错)

void __fastcall TForm2::Edit1KeyPress(TObject *Sender, char &Key)
{
if (Key==13)

ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from dhhm where dh='"+Edit1->Text.Trim()+"'or ch='"+Edit1->Text.Trim()+"'");
ADOQuery1->ExecSQL();
ADOQuery1->Active=true;
if (ADOQuery1->RecordCount==0)
{
Application->MessageBox("找不到该号码,请重新输入号码!","提示!",MB_OK&MB_ICONWARNING);
return;
}

return;


...全文
62 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdczwzq 2004-05-06
  • 打赏
  • 举报
回复
这个问题解决了 应该为
if (Key==13)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from dhhm where dh='"+Edit1->Text.Trim()+"'or ch='"+Edit1->Text.Trim()+"'");
ADOQuery1->ExecSQL();
ADOQuery1->Active=true;
if (ADOQuery1->RecordCount==0)

{Application->MessageBox("没有该号码,请再次输入!","查询结果!",MB_OK|MB_ICONINFORMATION);
Edit1->Text="";
return;
}
}
叶子哟 2004-05-06
  • 打赏
  • 举报
回复
ADOQuery1->Active=true;
修改为ADOQuery1->Open();
...
处理完成后用ADOQuery1->Close();

实在不行,你单步跟一下就知道错在哪儿了

JetKingLau 2004-05-06
  • 打赏
  • 举报
回复
if (Key!=13)
return;
gdczwzq 2004-05-06
  • 打赏
  • 举报
回复
还是不行,我本来的意思是用回车的时候才去执行的,可是现在我一打入一个数字,它就自动去执行,并且出错!急呀!!
叶子哟 2004-05-06
  • 打赏
  • 举报
回复
void __fastcall TForm2::Edit1KeyPress(TObject *Sender, char &Key)
{
if (Key==13)
{
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("select * from dhhm where dh='"+Edit1->Text.Trim()+"'or ch='"+Edit1->Text.Trim()+"'"); //建议用select count(*) as number ....
//ADOQuery1->ExecSQL();
ADOQuery1->Active=true;
if (ADOQuery1->RecordCount==0) //这儿还是判断是否有记录的数据比较好
{
Application->MessageBox("找不到该号码,请重新输入号码!","提示!",MB_OK&MB_ICONWARNING);
ADOQuery1->Active=false;
return;
}
ADOQuery1->Active=false;
}
return;

}

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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