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);      

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

  • 相关阅读:
    iOS热更新-8种实现方式
    HTTPS分析-简单易懂
    猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
    iOS的ATS配置
    Objective-C中block的底层原理
    iOS系列文章
    UIViewController生命周期-完整版
    缩放因子和UI设计
    iOS APP 如何做才安全
    逆向工程
  • 原文地址:https://www.cnblogs.com/gxwa/p/9798141.html
Copyright © 2011-2022 走看看