using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;
namespace Ray.BusinessRule
{
    public class LogicBase
    {
        protected Microsoft.Practices.EnterpriseLibrary.Data.Database db =
    Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase("CPDB");
        /// <summary>
        /// 根据传入的实体的值,进行联合查询
        /// </summary>
        /// <param name="source">包含查询条件的实体</param>
        /// <returns>包含查询结果的数据集</returns>
        public DataSet Search(Ray.SystemFramework.EntityBase source)
        {
            // 获取具体实体类的类型
            Type myType = source.GetType();// Type.GetType("source");
           PropertyInfo pi;
            // 定义T-sql语句的开头
            string sqlCom = "select * from " + source.TableName + " where 1=1 ";
           stringBuilder sbCondition = new StringBuilder();
            // 遍历实体所有属性
            foreach (object obj in source.Fields.Keys)
            {
              pi = myType.GetProperty(Convert.ToString(source.Fields[obj]));
              //System.Reflection.PropertyAttributes pa = pi.Attributes;
              object value = pi.GetValue(source, null);   // 获取属性值
                // 若属性值为空,跳过
                if (value == null)
                {
                    continue;
                }              // 否则拼接T-sql语句
                sbCondition.Append("and " + Convert.ToString(obj));  // 读取表字段名,查询条件为AND
                sbCondition.Append("='" + Convert.ToString(value) + "' ");  // 读取对应字段的值
            }
            // 生成T-sql命令字串
            sqlCom += sbCondition.ToString();
            // 调用Enterprise Library中Database的方法,执行sqlCom,并返回数据集
            return db.ExecuteDataSet(CommandType.Text, sqlCom);
        }
    }
}大哥大姐们,帮我看看,我的这个程序传入的是一个实体.然后用Relection得到他的类型,取得他的属性值,属性值是用Hashtable组织的.现在是红色部门的语句,老是在运行时报错:未将对象引用设置到对象的实例。
请大家指点一下,那里有问题啊!