MDB中,能不能把这几条SQL语句合起来写呢?
用ADOQuery控件
ADOQuery->SQL->Text="update qdda set xh=xh+1 where xh>="+IntToStr(xh);
ADOQuery->ExecSQL();
ADOQuery->SQL->Text="Select * From qdda order by xh";
ADOQuery->Open();
ADOQuery->SQL->Text="insert into qdda (xh) values("+IntToStr(xh)+")";
ADOQuery->ExecSQL();
ADOQuery->SQL->Text="Select * From qdda order by xh";
ADOQuery->Open();
//这样子写都没有问题,但 我想把几条SQL语句合起来写,也就是通过
ADOQuery->SQL->Add(...)来增加SQL,然后统一 ADOQuery->ExecSQL(); 行吗?
[解决办法]
写成存储过程不就完了吗?
[解决办法]
这是两次操作啊?没有必要合成一句吧..
[解决办法]
方法1:
//创建SQL脚本
TStringList *SQL = new TStringList();
SQL->Add("declare @xh as integer ");
SQL->Add("set @xh = "+xh+"");
SQL->Add("update qdda set xh=xh+1 where xh>=@xh ");
SQL->Add("Select * From qdda order by xh ");
//使用SQL脚本
Query1->Close();
Query1->SQL->Clear();
Query1->SQL->AddStrings(SQL);
Query1->Open();
方法2:
//SQL
Query1->SQL->Add("declare @xh as integer ");
Query1->SQL->Add("set @xh = :xh");
Query1->SQL->Add("update qdda set xh=xh+1 where xh>=@xh ");
Query1->SQL->Add("Select * From qdda order by xh ");
//使用
Query1->Close();
Query1->ParamByName("xh")->AsString = xh;
Query1->Open();