我通过SQL查询来的数据,用调用保存服务来插入到新建的单据中,怎样为单据中的字段赋值?我通过以下两种方式:
一、obj["FCardID"] = dr["FCardID"];
二、string fcardID = Convert.ToString(dr["FCardID"]);
info.GetField("FCardID").DynamicProperty.SetValue(obj, fcardID);
这两中方式都报错:从“System.Int64”到“Kingdee.BOS.Orm.DataEntity.DynamicObject”的强制转换无效。或
从“System.string”到“Kingdee.BOS.Orm.DataEntity.DynamicObject”的强制转换无效。
请教老师这个问题应该怎么解决?
源码:
string sql = @"select c.FCardID as FCardID,
a.FVALUE as FVALUES,L.FJIXIBILI as F_JIXIBILI,a.FVALUE*l.FJIXIBILI/100 as F_JZJF,GETDATE() as FCREATEDATE,'A' as FAUDITSTATUS from CMK_T_VIP_CARD c
inner join CMK_T_VIP_CardLevel l on c.FCARDLEVELID=l.FCardLevelID
inner join CMK_T_VIP_CARDACCTS a on c.FCardID=a.FCardID
where a.FVALUE<>0 and a.FACCOUNTID=2";
FormMetadata meta = MetaDataServiceHelper.Load(ctx, "PDKH_CMK_JZJF") as FormMetadata;
BusinessInfo info = meta.BusinessInfo;
DynamicObject obj = new DynamicObject(info.GetDynamicObjectType());
List
using (IDataReader dr = DBUtils.ExecuteReader(ctx, sql, param))
{
while (dr.Read())
{
string fcardID = Convert.ToString(dr["FCardID"]);
decimal FVALUES = Convert.ToDecimal(dr["FVALUES"]);
decimal F_JIXIBILI = Convert.ToDecimal(dr["F_JIXIBILI"]);
decimal F_JZJF = Convert.ToDecimal(dr["F_JZJF"]);
DateTime FCreateDate = Convert.ToDateTime(dr["FCreateDate"]);
string FAUDITSTATUS = Convert.ToString(dr["FAUDITSTATUS"]);
/* info.GetField("FCardID").DynamicProperty.SetValue(obj, fcardID);
info.GetField("FVALUES").DynamicProperty.SetValue(obj, FVALUES);
info.GetField("F_JIXIBILI").DynamicProperty.SetValue(obj, F_JIXIBILI);
info.GetField("F_JZJF").DynamicProperty.SetValue(obj, F_JZJF);
info.GetField("FCreateDate").DynamicProperty.SetValue(obj,
FCreateDate);
info.GetField("FAUDITSTATUS").DynamicProperty.SetValue(obj, 'A');*/
obj["FCardID"] = dr["FCardID"];
obj["FVALUES"]=FVALUES;
obj["F_JIXIBILI"]=F_JIXIBILI;
obj["F_JZJF"]=F_JZJF;
obj["FCreateDate"]=FCreateDate;
obj["FAUDITSTATUS"] = FAUDITSTATUS;
BusinessDataServiceHelper.Save(ctx, obj);
}
}/*
foreach (DataRow row in dataSet.Tables[0].Rows)
{
foreach (DataTable dt in dataSet.Tables)
foreach (DataRow dr in dt.Rows)
foreach (DataColumn dc in dr.Table.Columns) */
}
推荐阅读