标题:数据插入,列名太多,如何简化代码!请大神指教
只看楼主
弦外之语
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-8-31
结帖率:100%
 问题点数:0 回复次数:1 
数据插入,列名太多,如何简化代码!请大神指教
    try
        with ADOQuery1 do
        begin
            try
                close;
                SQL.Clear;
                SqlStr := 'insert into t_wmdz (chxdh,cBGDH,cQYG,dTGRQ,cMYFS,nHYF';
                SqlStr :=  SqlStr + ',nSJHYF,nSJGNYF,dTDRQ,cKHMC,cKHJL,dHXDSLRQ';
                SqlStr :=  SqlStr + ',cXYZH,dYHJDRQ,dTSRQ,cFPH,dBGRQ,cMDG,dCYRQ,nZF';
                SqlStr :=  SqlStr + ',nBXF,nSJBXF,dHXRQ,dSQTSRQ,cYWB,cKFZL,dHXTDRQ,dXYZQX,cJDYH';
                SqlStr :=  SqlStr + ',nTSJE,cXSLX,nBGMS,nBGJZ,nBGZJE,nFOBJE,nKTSJE,nSJYSJE,nQKJE';
                SqlStr :=  SqlStr + ',dZCSKRQ,cKFZG,cDZY,cTDH,dTIDRQ,nSJFHSL,cSJJLDW,nSJJZ,nSJDZJE,cMH)';
                SqlStr :=  SqlStr + ' values ';
                SqlStr :=  SqlStr + '('''+cxTextHXDH.text+''','''+cxTextEdit2.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit3.text+''','''+cxComboBox2.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox1.text+''','''+cxTextEdit4.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit5.text+''','''+cxTextEdit6.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox3.text+''','''+cxTextEdit7.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit8.text+''','''+cxComboBox4.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit9.text+''','''+cxComboBox8.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox9.text+''','''+cxTextEdit10.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox5.text+''','''+cxTextEdit11.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit12.text+''','''+cxTextEdit13.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit14.text+''','''+cxTextEdit15.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox6.text+''','''+cxComboBox7.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit16.text+''','''+cxTextEdit17.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox10.text+''','''+cxComboBox11.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit18.text+''','''+cxTextEdit19.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox14.text+''','''+cxTextEdit25.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit26.text+''','''+cxTextEdit27.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit28.text+''','''+cxTextEdit29.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit32.text+''','''+cxTextEdit33.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox13.text+''','''+cxTextEdit20.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit21.text+''','''+cxTextEdit22.text+''',';
                SqlStr :=  SqlStr + ''''+cxComboBox12.text+''','''+cxTextEdit23.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit24.text+''','''+cxTextEdit30.text+''',';
                SqlStr :=  SqlStr + ''''+cxTextEdit31.text+''','''+cxMemo1.Text+''')';
                SQL.Add(SqlStr);
                ExecSQL
            finally
                Close;
            end;
        end;
        showmessage('保存成功');
    except

    end;
搜索更多相关主题的帖子: insert close 如何 
2016-06-01 11:10
jopiter
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-4-12
得分:0 
insert into t_wmdz values(......)
2016-07-06 13:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465464-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013831 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved