今天在PMOMMABW34画面材料申请收池点查询报错,查了好久才发现是类型转换错误,期初以为是日期格式转换错误,打了日志发现日期SubString截取并无问题,查了很久发现是数据库读取查询出来的字段时使用getString(1)获取字段值发生了错位,把整形读成了sting类型,代码如下
while (cmd_tpmommabw01_group.Read()) { Log::Trace("", __FUNCTION__, "********开始读取数据[{0}]", ""); tpmommabw01.Reset(); /*tpmommabw01.APP_STATUS = cmd_tpmommabw01_group.GetString(1); tpmommabw01.ST_NO = cmd_tpmommabw01_group.GetString(2); tpmommabw01.ORDER_NO = cmd_tpmommabw01_group.GetString(3); tpmommabw01.INGOT_CODE = cmd_tpmommabw01_group.GetString(4); tpmommabw01.PREC_PONO = cmd_tpmommabw01_group.GetString(5); tpmommabw01.FACTORY_DIV = cmd_tpmommabw01_group.GetString(6); total_mat_wt = cmd_tpmommabw01_group.GetDecimal(7); total_mat_num = cmd_tpmommabw01_group.GetDecimal(8);*/ tpmommabw01.APP_STATUS = cmd_tpmommabw01_group.GetString(1); tpmommabw01.ST_NO = cmd_tpmommabw01_group.GetString(2); tpmommabw01.LG_ST = cmd_tpmommabw01_group.GetString(3); tpmommabw01.ORDER_NO = cmd_tpmommabw01_group.GetString(4); tpmommabw01.INGOT_CODE = cmd_tpmommabw01_group.GetString(5); tpmommabw01.PREC_PONO = cmd_tpmommabw01_group.GetString(6); tpmommabw01.FACTORY_DIV = cmd_tpmommabw01_group.GetString(7); total_mat_wt = cmd_tpmommabw01_group.GetDecimal(8); total_mat_num = cmd_tpmommabw01_group.GetDecimal(9); Log::Trace("", __FUNCTION__, "tpmommabw01.APP_STATUS[{0}]", tpmommabw01.APP_STATUS); Log::Trace("", __FUNCTION__, "tpmommabw01.ST_NO[{0}]", tpmommabw01.ST_NO); Log::Trace("", __FUNCTION__, "tpmommabw01.LG_ST[{0}]", tpmommabw01.LG_ST); Log::Trace("", __FUNCTION__, "tpmommabw01.ORDER_NO[{0}]", tpmommabw01.ORDER_NO); Log::Trace("", __FUNCTION__, "tpmommabw01.INGOT_CODE[{0}]", tpmommabw01.INGOT_CODE); Log::Trace("", __FUNCTION__, "tpmommabw01.PREC_PONO[{0}]", tpmommabw01.PREC_PONO); Log::Trace("", __FUNCTION__, "tpmommabw01.FACTORY_DIV[{0}]", tpmommabw01.FACTORY_DIV); Log::Trace("", __FUNCTION__, "total_mat_wt[{0}]", total_mat_wt); Log::Trace("", __FUNCTION__, "total_mat_num[{0}]", total_mat_num); CString sql_tpmommabw01_inq = "select * " " from tpmommabw01" " where app_status = @app_status " " and st_no = @st_no " "and lg_st=@lg_st" " and order_no = @order_no " " and ingot_code = @ingot_code " " and prec_pono = @prec_pono " " and factory_div = @factory_div " " order by mat_no "; Log::Trace("", __FUNCTION__, "********sql_tpmommabw01_inq[{0}]", sql_tpmommabw01_inq); CDbCommand cmd_tpmommabw01_inq(sql_tpmommabw01_inq, conn); cmd_tpmommabw01_inq.Parameters.Set("app_status", tpmommabw01.APP_STATUS); cmd_tpmommabw01_inq.Parameters.Set("st_no", tpmommabw01.ST_NO); //cmd_tpmommabw01_inq.Parameters.Set("lg_st", v_lg_st); cmd_tpmommabw01_inq.Parameters.Set("lg_st", tpmommabw01.LG_ST); cmd_tpmommabw01_inq.Parameters.Set("order_no", tpmommabw01.ORDER_NO); cmd_tpmommabw01_inq.Parameters.Set("ingot_code", tpmommabw01.INGOT_CODE); cmd_tpmommabw01_inq.Parameters.Set("prec_pono", tpmommabw01.PREC_PONO); cmd_tpmommabw01_inq.Parameters.Set("factory_div", tpmommabw01.FACTORY_DIV); cmd_tpmommabw01_inq.ExecuteReader(); if (cmd_tpmommabw01_inq.Read()) { Log::Trace("", __FUNCTION__, "********读取cmd_tpmommabw01_inq数据[{0}]", ""); cmd_tpmommabw01_inq.Fetch(tpmommabw01); CDataRow& row = bcls_ret->Tables[0].Rows.Add(); row.Merge(tpmommabw01); if (!bcls_ret->Tables[0].Columns.Contains("TOTAL_WT")) { bcls_ret->Tables[0].Columns.Add(DT_DECIMAL, "TOTAL_WT"); } if (!bcls_ret->Tables[0].Columns.Contains("TOTAL_NUM")) { bcls_ret->Tables[0].Columns.Add(DT_DECIMAL, "TOTAL_NUM"); } if (!bcls_ret->Tables[0].Columns.Contains("CAST_NUM")) { bcls_ret->Tables[0].Columns.Add(DT_DECIMAL, "CAST_NUM"); } row["TOTAL_WT"] = total_mat_wt; row["TOTAL_NUM"] = total_mat_num; row["CAST_NUM"] = total_mat_num; v_total_count++; Log::Trace("", __FUNCTION__, "********结束读取cmd_tpmommabw01_inq数据[{0}]", ""); } Log::Trace("", __FUNCTION__, "********结束读取数据[{0}]", ""); cmd_tpmommabw01_inq.Close(); } cmd_tpmommabw01_group.Close(); //返回的记录数。 fetchRowCount = v_total_count;
//读取字段顺序,代码中注释的读取不对 app_status ,st_no, lg_st, order_no ingot_code ,prec_pono ,factory_div, sum(mat_wt), sum(mat_num) ,prec_melt_lot_no
页面报错string fromat error解决方法以及思路
原文:https://www.cnblogs.com/yjy1412/p/14608803.html