项目场景:
每个语言都有每个语言的特点 我在c#项目中遇到了一个问题,数据库字段长度限制所以这个字段存储查询分数字和汉字,但是渲染要统一为了代码简洁用到了eplace函数
解决方案:
SELECT
row_number ( ) OVER ( ORDER BY fl.DID ASC ) AS rownumber,
f.DEV_AD,
fl.Online,
fl.HEAT,
fl.HEAT_POWER,
fl.TOTAL_FLOW,
fl.INSTANT_FLOW,
fl.TEMP_WATER_IN,
fl.TEMP_WATER_OUT,
fl.Error,
fl.RTime,
fl.Record_Time
FROM
Dev AS fl
LEFT JOIN ( SELECT DID, DEV_AD FROM Devr ) AS f ON fl.DID= f.DID
LEFT JOIN ( SELECT FLOWMETER_ID, village, building, unit, room FROM Room ) r ON f.DID = r.FLOWMETER_ID
WHERE
village = '{1}'
这里查询用到了一个字段error是错误 数据不便修改所以只能修改代码
DataTable dt = sqlHelper.QueryTable(sql, parameters);
if (dt == null) return list;
foreach (DataRow row in dt.Tables[0].Rows)**/
{
FlowmeterTempData ftd = new FlowmeterTempData();
ftd.building = building;
ftd.DEV_AD = row["DEV_AD"].ToString();
ftd.Online = row["Online"].ToString() == "False" ? "断线" : "正常"; ;
ftd.HEAT = row["HEAT"].ToString();
ftd.HEAT_POWER = row["HEAT_POWER"].ToString();
ftd.TOTAL_FLOW = row["TOTAL_FLOW"].ToString();
ftd.INSTANT_FLOW = row["INSTANT_FLOW"].ToString();
ftd.TEMP_WATER_IN = Convert.ToDouble(row["TEMP_WATER_IN"]);
ftd.TEMP_WATER_OUT = Convert.ToDouble(row["TEMP_WATER_OUT"]);
ftd.Error = row["Error"].ToString();
ftd.Error.Replace("0", "温度突变");
ftd.Error.Replace("1", "ntc故障");
ftd.Error.Replace("2", "无线故障");
ftd.Error.Replace("3", "通信故障");
ftd.Error.Replace("4", "控制异常");
ftd.Error.Replace("5", "电池电压低");
ftd.Error.Replace("6", "阀门堵转");
ftd.RTime = row["RTime"].ToString();
ftd.Record_Time = row["Record_Time"].ToString();
list.Add(ftd);
}
ftd.Error = row["Error"].ToString();
ftd.Error.Replace("0", "温度突变");
ftd.Error.Replace("1", "ntc故障");
ftd.Error.Replace("2", "无线故障");
ftd.Error.Replace("3", "通信故障");
ftd.Error.Replace("4", "控制异常");
ftd.Error.Replace("5", "电池电压低");
ftd.Error.Replace("6", "阀门堵转");
这个就是要介绍的 所以不管是什么只需要使用函数看它是不是数字是的话就会对应的转为汉字不是的话就是原字符串