asp.net 实体类 存入 数据库
using System.Reflection;
ChaJiLuchajilu=newChaJiLu();
chajilu.weiZhangDate="2018-08-08";
chajilu.weiZhangQuYu="123";
chajilu.weiZhangXingWei="ddddddd";
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;//将属性名称赋值给临时变量
if (pi.GetValue(chajilu, null) != null)
{
value = pi.GetValue(chajilu, null).ToString();
}
else
{
value = "";
}
leftStr += tempName + ",";
rightStr +="'"+ value + "',";
}
leftStr = leftStr.Remove(leftStr.ToString().LastIndexOf(','), 1);
rightStr = rightStr.Remove(rightStr.ToString().LastIndexOf(','), 1);
cmdStr += leftStr + ") values " + rightStr + ")";
sqlhelper.cmdNoQuery(cmdStr);