联系我们

为客户提供超预期的高品质网站设计!

asp.net 实体类 存入 数据库

2018-6-17 0:00:00

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);

上一条新闻:.net发送post请求
下一条新闻:图片base64格式,另存为图片

 

4008-520-214 54057491 info@maolian.net