糟糕!前些日子自己写了一段代码,现在忘了什么意思了!昏倒!大家帮忙看看!!!

woki 2002-05-18 02:05:05
好象是往一张基本表赋值

Query1->Close();
Query1->SQL->Clear();

switch (StringGrid1->ColCount)
{
case 3:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc)");break;
case 4:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd)");break;
case 5:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee)");break;
case 6:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff)");break;
case 7:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg)");break;
case 8:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh)");break;
case 9:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii)");break;
case 10:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj)");break;
case 11:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk)");break;
case 12:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll)");break;
case 13:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm)");break;
case 14:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn)");break;
case 15:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo)");break;
case 16:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp)");break;
case 17:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq)");break;
case 18:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr)");break;
case 19:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss)");break;
case 20:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt)");break;
case 21:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu)");break;
case 22:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu,:vv)");break;
case 23:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu,:vv,:ww)");break;
case 24:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu,:vv,:ww,:xx)");break;
case 25:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu,:vv,:ww,:xx,:yy)");break;
case 26:Query1->SQL->Add("Insert into PrintDemo values (:aa,:bb,:cc,:dd,:ee,:ff,:gg,:hh,:ii,:jj,:kk,:ll,:mm,:nn,:oo,:pp,:qq,:rr,:ss,:tt,:uu,:vv,:ww,:xx,:yy,:zz)");break;
}

for (i=1;i<StringGrid1->RowCount;i++)
{
for (j=0;j<Query1->ParamCount;j++)
Query1->Params->Items[j]->AsString=StringGrid1->Cells[j][i];
Query1->ExecSQL();
}

// 基本表PrintDemo赋值


最下面的两重循环什么意思啊??下次我一定注意加上注释!!
:(
...全文
48 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
woki 2002-05-19
我觉得奇怪的地方是当初为什么把Query1->ExecSQL()写在循环内。。。

有哪位解释一下吗?我还是没想明白Query1->ExecSQL()的循环效率问题
  • 打赏
  • 举报
回复
whitelion 2002-05-19
是够糟的
  • 打赏
  • 举报
回复
我不懂电脑 2002-05-18
同意dybcb()
  • 打赏
  • 举报
回复
dybcb 2002-05-18
整段代码的意思是判断StringGrid中列的数目,然后根据StringGrid中列的数目分别合成不同的数据库插入语句,最后两个循环的意思是把遍历StringGrid中的所有行,并把所有行的内容都插入到数据库中
  • 打赏
  • 举报
回复
woki 2002-05-18
就是说是准备插入的参数赋值哦?

执行为什么要很多句呢?这样看来只要一句执行不就可以了吗?
  • 打赏
  • 举报
回复
hotxu 2002-05-18
//将StringGrid1中的数据插入PrintDemo表中。
for (i=1;i<StringGrid1->RowCount;i++)//控件StringGrid的行数
{
for (j=0;j<Query1->ParamCount;j++)//控件StringGrid的列数
Query1->Params->Items[j]->AsString=StringGrid1->Cells[j][i];
Query1->ExecSQL();
}
  • 打赏
  • 举报
回复
li_aiwu 2002-05-18
并不是查询,是给sql语句的参数变量赋值(如:aa,bb,cc……)!再执行插入操作!
  • 打赏
  • 举报
回复
chzhli186858 2002-05-18
for (i=1;i<StringGrid1->RowCount;i++) //控件StringGrid的行数
{
for (j=0;j<Query1->ParamCount;j++) //控件StringGrid的列数
Query1->Params->Items[j]->AsString=StringGrid1->Cells[j][i]; //用控件StringGrid1里的数查询
Query1->ExecSQL();执行查询
}
  • 打赏
  • 举报
回复
相关推荐
发帖
C++ Builder

1.3w+

社区成员

C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
帖子事件
创建了帖子
2002-05-18 02:05
社区公告
暂无公告