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

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

转载于:https://www.cnblogs.com/gxwa/p/9798141.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值