zoukankan      html  css  js  c++  java
  • Mysql一次更新多条数据

    根据不同的ID更新ID对应条的Code,Name,Value,Type:

    string updateSqlString = " update serverconfigdata set ";
    string updateSqlCode = " Code = CASE ID ";
    string updateSqlName = " Name = CASE ID ";
    string updateSqlValue = " Value = CASE ID ";
    string updateSqlType = " Type = CASE ID ";

    foreach (ServerConfigData sc in scList)
    {
    if(!string.IsNullOrEmpty(sc.ID))
    {
    //updateSqlString = $" update tablename set Code = '{sc.Code}',Name = '{sc.Name}',Value = '{sc.Value}',Type = '{sc.Type}' where Code = '{sc.Code}'; ";
    //DataTable updatedt = mySQLConn.ExecuteDataTable(updateSqlString);
    updateSqlCode += $" When {sc.ID} Then '{sc.Code}' ";
    updateSqlName += $" When {sc.ID} Then '{sc.Name}' ";
    updateSqlValue += $" When {sc.ID} Then '{sc.Value}' ";
    updateSqlType += $" When {sc.ID} Then '{sc.Type}' ";

    updateIDS += $"{sc.ID},";
    }
    else
    {
    insertSqlDatas += $" ('{sc.Code}','{sc.Name}','{sc.Value}','{sc.Type}'),";
    }
    }
    updateSqlCode += " END ";
    updateSqlName += " END ";
    updateSqlValue += " END ";
    updateSqlType += " END ";

  • 相关阅读:
    Java集合框架
    数字翻转
    Servlet的一些细节
    tomcat9配置https
    JavaWeb_打包web应用war
    JavaWeb_tomcat设置默认应用
    JavaWeb_增强for循环
    JavaWeb_静态导入、自动拆箱/装箱
    JavaWeb_泛型(Generic)
    54字符流中第一个不重复的字符
  • 原文地址:https://www.cnblogs.com/wa502/p/11603276.html
Copyright © 2011-2022 走看看