有关TQuery的查询与插入的问题,有些头痛!

wolf416 wolf416 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用TQuery,TDataSource和TDBGrid,通过SQL将所查询的记录放在TDBGrid中,另外也通过SQL将记录插入表中,但插入所用的表与查询所用的表是相同的表。
但在不断有记录插入的时候,界面不断地闪烁,有时也出现违例,不知应该怎么办?
查询和插入的代码如下:
void __fastcall TfrmLog::ButtonQueryClick(TObject *Sender)
{
try{
AnsiString s;
AnsiString strQuery;
AnsiString strUser;
AnsiString strType;
AnsiString strSortName;
AnsiString strSortType;
strSortName=ComboBoxSort->Text;
if(RadioButtonASC->Checked)
strSortType="ASC";
else
strSortType="DESC";

if(ComboBoxUser->Text=="All User")
strUser="%";
else strUser=ComboBoxUser->Text;
if(ComboBoxType->Text=="All Type")
strType="%";
else strType=ComboBoxType->Text;

s= "where OperateTime>'"+Edit1->Text+"'" +" And OperateTime <'"+Edit2->Text+"'";
s+=" and UserName like '"+strUser+"'";
s+=" and Type like '"+strType+"'";
strDeleteCondition=s;
s+=" Order by "+strSortName;
s+=" "+strSortType;
strQueryCondition=s;
strQuery="select * from logs "+strQueryCondition;
LogQuery->Close();
LogQuery->SQL->Clear();
LogQuery->SQL->Add(strQuery);
LogQuery->Open();
}
catch(...)
{
ShowMessage("Query DB failed!");
}
}

void __fastcall TfrmLog::InsertLogToDB(PLOGRECORD plr)
{

try{
LogQuery->Close();
LogQuery->SQL->Clear();
LogQuery->SQL->Add("Insert into logs(UserName,Type,Target,Operation) ");
LogQuery->SQL->Add(" values(:UserName,:Type,:Target,:Operation)");
LogQuery->ParamByName("UserName")->AsString=plr->strUser;
LogQuery->ParamByName("Type")->AsString=plr->strType;
LogQuery->ParamByName("Target")->AsString=plr->strTarget;
LogQuery->ParamByName("Operation")->AsString=plr->strOperation;
if(!LogQuery->Prepared)
LogQuery->Prepare();
LogQuery->ExecSQL();

}
catch(...)
{

ShowMessage("Insert a record to DB failed!");
}

}
...全文
评论 3
收藏 已收藏
分享
返回顶部
wolf416
C++ Builder 13,871 成员 102,696 内容