zoukankan      html  css  js  c++  java
  • C# string.formate() 中 如何使用string 循环出来的一串字符

    在C#中我们会遇到 string.formate()中的sql语句的所使用的字段和和赋值,都有可能从字典表中和其他表中得到,而就需要循环表字段和使用占位符进行赋值,一般我们可能会使用sting name+=“2,3,4,5,”等,,但是在string。formate中是不行的

    可以把string定义成数组类型就可以了:下面是我所遇到的问题:

    //这里循环的set 所使用的字段
    sql = string.Format("update MonthBill set  ");
    int count = 0;
    for (int dic1 = 0; dic1 < dic_ids.Length; dic1++)//set  的字段
    {
        sql += dic_ids[dic1] + " = {"+count+"} ,";
        count++;
    }
    //定义数组
    string [] snum=new string[100];
    for (int dicid = 0; dicid < names.Length; dicid++)//set 字段=的值
    {
        if (dicid == names.Length - 1)
        {
            //循环占位的数据  也就是平时所使用的string name="1,2,3,4,4";里面的数据
            snum[dicid] += pds.Rows[i][names[dicid]].ToString();
            total += Convert.ToDouble(pds.Rows[i][names[dicid]].ToString());
        }
        else
        {
            snum[dicid] += pds.Rows[i][names[dicid]].ToString();
            total += Convert.ToDouble(pds.Rows[i][names[dicid]].ToString());
        }
    }
    //对数据进行拼接
    sql +=" totalmoney='" + total + "'  where cYear='" + cYear + "' and cMonth='" + cmonth + "' and telecode='" + telecode01 + "'";
    sql = string.Format(sql, snum);
    sqllist.Add(sql);      

    也许不是最好的解决方式,至少可以解决当前问题

  • 相关阅读:
    barcode制作条形码及破解
    软件敏捷架构师
    软件需求分析三步走
    GDI+显示GIF动画
    CSpinButtonCtrl的弱智问题
    [C++] STL里面的map
    [C#] 再议Exception
    [C++] unsigned是麻烦制造者
    用GDI+转BMP为WMF、EXIF、EMF格式
    [C++] 编译时的warning
  • 原文地址:https://www.cnblogs.com/gxwa/p/9798141.html
Copyright © 2011-2022 走看看