首页 > 编程 > .NET > 正文

asp.net 反射减少代码书写量

2024-07-10 12:45:12
字体:
来源:转载
供稿:网友

  代码如下:
public bool Add(Liuyan refmodel)
    {
        string sql = "insert into liuyan(name,phone,zhiwei,gongsi,addr,country,dianyou,content,adddate)values(@name,@phone,@zhiwei,@gongsi,@addr,@country,@dianyou,@content,@adddate)";
        OleDbParameter[] parameters ={
            new OleDbParameter("@name",OleDbType.VarChar),
            new OleDbParameter("@tel",OleDbType.VarChar),
            new OleDbParameter("@zhiwei",OleDbType.VarChar),
            new OleDbParameter("@gongsi",OleDbType.VarChar),
            new OleDbParameter("@addr",OleDbType.VarChar),
            new OleDbParameter("@country",OleDbType.VarChar),
            new OleDbParameter("@dianyou",OleDbType.VarChar),
            new OleDbParameter("@content",OleDbType.VarChar),
            new OleDbParameter("@adddate",OleDbType.VarChar)
        };
        parameters[0].Value=model.Xingming;
        parameters[1].Value=model.Tel;
        parameters[2].Value=model.Zhiwei;
        parameters[3].Value=model.Gongsi;
        parameters[4].Value=model.Addr;
        parameters[5].Value=model.Country;
        parameters[6].Value=model.Dianyou;
        parameters[7].Value=model.Content;
        parameters[8].Value=model.Adddate;
        return sqlHelper.executeCommand(sql, parameters);
    }
 
本文讲反射 现在就说在这段代码的哪个位置使用反射 只是本人编码过程中为了省劲突发奇想
代码如下:
   parameters[0].Value=model.Xingming;
        parameters[1].Value=model.Tel;
        parameters[2].Value=model.Zhiwei;
        parameters[3].Value=model.Gongsi;
        parameters[4].Value=model.Addr;
        parameters[5].Value=model.Country;
        parameters[6].Value=model.Dianyou;
        parameters[7].Value=model.Content;

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表