did you recompile everything? what's in GetProductDetails? try to single step into the code

解决方案 »

  1.   

    强转换:
    IBuySpy.ProductDetails myProductDetails = (IBuySpy.ProductDetails)products.GetProductDetails(ProductID);
      

  2.   

    看看你的GetProductDetails方法的定义!应该是这样的! public ProductDetails GetProductDetails(int productID)
    {}
      

  3.   

    谢谢各位,可是问题仍然存在。
    我照   kinglht(爱新觉罗至尊宝) 兄的方法试了,但是出错信息是一样的。
    另外,我想请教如何单步跟踪? 我的机器太旧了,用不起Visual Studio.net, 是不是一定要这个才行?下面我贴出ProductsDB类的声明,以及他的GetProductDetails()方法,还请大哥们帮我诊断一下(非是小弟我懒,实在是因为对.net刚刚接触,调试经验太少):public class ProductsDB {
    .....
            public ProductDetails GetProductDetails(int productID) {            // 创建连接,命令物体
                SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
                SqlCommand myCommand = new SqlCommand("ProductDetail", myConnection);            // 命令为存储过程
                myCommand.CommandType = CommandType.StoredProcedure;            // 添加参数到存储过程
                SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
                parameterProductID.Value = productID;
                myCommand.Parameters.Add(parameterProductID);
        
    // 原价
                SqlParameter parameterUnitCost = new SqlParameter("@UnitCost", SqlDbType.Money, 8);
                parameterUnitCost.Direction = ParameterDirection.Output; //输出参数
                myCommand.Parameters.Add(parameterUnitCost);
                
    // 会员价
    SqlParameter parameterMemberCost = new SqlParameter("@MemberCost", SqlDbType.Money, 8);
    parameterMemberCost.Direction = ParameterDirection.Output; //输出参数
    myCommand.Parameters.Add(parameterMemberCost); // 型号
                SqlParameter parameterModelNumber = new SqlParameter("@ModelNumber", SqlDbType.NVarChar, 50);
                parameterModelNumber.Direction = ParameterDirection.Output; //输出参数
                myCommand.Parameters.Add(parameterModelNumber);
                
    // 商品名称
                SqlParameter parameterModelName = new SqlParameter("@ModelName", SqlDbType.NVarChar, 50);
                parameterModelName.Direction = ParameterDirection.Output; //输出参数
                myCommand.Parameters.Add(parameterModelName); // 商品尺寸
    SqlParameter parameterModelSize = new SqlParameter("@ModelSize", SqlDbType.NVarChar, 50);
    parameterModelSize.Direction = ParameterDirection.Output; //输出参数
    myCommand.Parameters.Add(parameterModelSize); // 商品图片
                SqlParameter parameterProductImage = new SqlParameter("@ProductImage", SqlDbType.NVarChar, 50);
                parameterProductImage.Direction = ParameterDirection.Output; //输出参数
                myCommand.Parameters.Add(parameterProductImage);

                // 商品描述
    SqlParameter parameterDescription = new SqlParameter("@Description", SqlDbType.NVarChar, 3800);
                parameterDescription.Direction = ParameterDirection.Output; //输出参数
                myCommand.Parameters.Add(parameterDescription);
        
    // 库存数量
    SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4);
    parameterQuantity.Direction = ParameterDirection.Output; //输出参数
    myCommand.Parameters.Add(parameterQuantity);
        
                // 打开连接,执行命令
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                myConnection.Close();            // 用存储过程的输出填充到 ProductDetails 结构
                ProductDetails pd = new ProductDetails();            pd.ModelNumber = (String)parameterModelNumber.Value;
                pd.ModelName = (String)parameterModelName.Value;
    pd.ModelSize = ((String)parameterModelSize.Value).Trim();
                pd.ProductImage = ((String)parameterProductImage.Value).Trim();
                pd.UnitCost = (decimal)parameterUnitCost.Value;
    pd.MemberCost = (decimal)parameterMemberCost.Value;
                pd.Description = ((String)parameterDescription.Value).Trim();
    pd.Quantity = (int)parameterQuantity.Value;            return pd;
            }
      

  4.   

    ProductDetails 类和products.GetProductDetails(ProductID); 返回的对象不是同样的GetProductDetails 这个函数中是怎么定义的,返回值是不是ProductDetails 类型的
      

  5.   

    to : xiongliang2003
    是同一个类型的啊,这一句:
             // 用存储过程的输出填充到 ProductDetails 结构
                ProductDetails pd = new ProductDetails();          ...
              return pd;
      

  6.   

    IBuySpy.ProductsDB.GetProductDetails(Int32 productID)
    在调用前对变量productID强制类型转换为INT32    productID=Convert.Int32(productID)
      

  7.   

    试了 ProductID = Convert.ToInt32(ProductID);
    还是一样的错误~哪位大哥能救救我啊?
      

  8.   

    did you compile the cs file into a dll???
      

  9.   

    我每次修改后都重新运行了make.bat,生成了新的dll文件.
      

  10.   

    check the bin subdirectory, make the dll is updated, from what I read here, the type doesn't match, that could only happen1. if you have modified the namespace/class name
    2. the dll loaded at runtime is the old one
      

  11.   

    多谢思归大哥的关注,我没有修改名称空间,但是数据库名字变了。请问这和 dll 的文件名有关系么?
    我有点疑惑的地方是,运行时,程序是如何判断哪个类在哪个dll 中的?
      

  12.   

    数据库名字 should not matter, as long as it existsopen a dos window, go to bin subdirectory, look for any new dll and runildasm yourdll.dll