今天我们来学习学习通过反射技术来生成SQL语句. 反射提供了封装程序集.模块和类型的对象.您可以使用反射动态地创建类型的实例,将类型绑定到现有对象,或从现有对象中获取类型.然后,可以调用类型的方法或访问其字段和属性. 1.先建立实体类 用户实体类: public class User { public int id { get; set; } public string UserName { get; set; } public string Password { get; set; } pub…
----------------------------------------Program.cs---------------------------------------- using System;using System.Collections.Generic;using System.Text;//反射命名空间using System.Reflection;namespace Test{ class Program { static void Main(s…
public static int Reg(Model ml) { bool b = true; Visit vt = new Visit(); StringBuilder builder = new StringBuilder("insert into UsersTable ("); Type type = ml.GetType(); PropertyInfo[] per = type.GetProperties(); List<SqlParameter> sqlpar…
转:http://www.cnblogs.com/the7stroke/archive/2012/04/22/2465597.html using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Data; public class SQLHelper { /// <summary> /// 插入单个实例 /…