zoukankan      html  css  js  c++  java
  • 先组装字符串再拆分,加强通用性

     1function prepareSql()
     2        {                   
     3          var numstr = "";
     4          var chrstr = "";
     5          numstr = numstr + "xed|" + "0" + "^";
     6          numstr = numstr + "checkflag|" + "0" + "^";
     7          numstr = numstr + "endcheck|" + "0" + "^";
     8          numstr = numstr + "fbuilder|" + myform.txtfbuilder.title + "^";
     9          numstr = numstr + "ftime|" + document.getElementById("txtftime").options[document.getElementById("txtftime").selectedIndex].value + "^";
    10          numstr = numstr + "fexampaper|" + myform.txtfexampapername.title + "^";
    11          numstr = numstr.substring(0,numstr.length-1);
    12          chrstr = chrstr + "fstime|" + document.all("txtfstime").value + "^"    ;
    13          chrstr = chrstr + "fetime|" + document.all("txtfetime").value + "^"    ;
    14         
    15          chrstr = chrstr + "fdesc|" + document.all("txtfdesc").value + "^"    ;
    16          chrstr = chrstr + "fname|" + document.all("txtfname").value + "^"    ;
    17          chrstr = chrstr + "fworkitem|" + document.all("txtfworkitem").value + "^"
    18          chrstr = chrstr + "fbak3|" + document.all("txtfbuilder").value + "^"    ;
    19          chrstr = chrstr.substring(0,chrstr.length-1);
    20          if (document.getElementById("action").innerText=="insert")
    21          {
    22            Insert("0",numstr,chrstr,myform.txtfname.value);
    23          }

    24          else
    25          {            
    26            Insert(myform.fid.value,numstr,chrstr,myform.txtfname.value);
    27          }

    28          

    执行SQL语句时,再将传递过来的字符串进行拆分组装
     1            If numstr <> "" Then
     2                Cy = Split(numstr, "^")
     3                For i = 0 To UBound(Cy)
     4                    Cytmp = Split(Cy(i), "|")
     5                    colstr = colstr & Cytmp(0& ","
     6                    valuestr = valuestr & Cytmp(1& ","
     7                Next
     8            End If
     9            If chrstr <> "" Then
    10                Cy = Split(chrstr, "^")
    11                For i = 0 To UBound(Cy)
    12                    Cytmp = Split(Cy(i), "|")
    13                    colstr = colstr & Cytmp(0& ","
    14                    valuestr = valuestr & "'" & Cytmp(1& "',"
    15                Next
    16            End If
    17            colstr = Left(colstr, Len(colstr) - 1)
    18            valuestr = Left(valuestr, Len(valuestr) - 1)
    19            mySql = " insert into tblexamplanmain (fid," & colstr & ")" & "  values(" & maxid & "," & valuestr & ")"
  • 相关阅读:
    牛客小白月赛21
    牛客小白月赛21
    CodeForces 1333-C Eugene and an array(子区间和为0、前缀和)
    页面大小、页表项、虚拟地址和物理地址之间的关系(转)
    001-Paint_FreePythonGames项目代码详解(每行都有注释!!!)
    第17讲~第19讲:函数:python的乐高积木
    第16讲:序列!序列!
    第15讲:字符串格式化
    练习23--字符串、字节和编码
    第14讲:字符串--各种奇葩内置方法
  • 原文地址:https://www.cnblogs.com/xiang/p/249763.html
Copyright © 2011-2022 走看看