"指定的转换无效“,郁闷!(请思归等高手指教) did you recompile everything? what's in GetProductDetails? try to single step into the code 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 强转换:IBuySpy.ProductDetails myProductDetails = (IBuySpy.ProductDetails)products.GetProductDetails(ProductID); 看看你的GetProductDetails方法的定义!应该是这样的! public ProductDetails GetProductDetails(int productID){} 谢谢各位,可是问题仍然存在。我照 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; } ProductDetails 类和products.GetProductDetails(ProductID); 返回的对象不是同样的GetProductDetails 这个函数中是怎么定义的,返回值是不是ProductDetails 类型的 to : xiongliang2003是同一个类型的啊,这一句: // 用存储过程的输出填充到 ProductDetails 结构 ProductDetails pd = new ProductDetails(); ... return pd; IBuySpy.ProductsDB.GetProductDetails(Int32 productID)在调用前对变量productID强制类型转换为INT32 productID=Convert.Int32(productID) 试了 ProductID = Convert.ToInt32(ProductID);还是一样的错误~哪位大哥能救救我啊? did you compile the cs file into a dll??? 我每次修改后都重新运行了make.bat,生成了新的dll文件. 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 name2. the dll loaded at runtime is the old one 多谢思归大哥的关注,我没有修改名称空间,但是数据库名字变了。请问这和 dll 的文件名有关系么?我有点疑惑的地方是,运行时,程序是如何判断哪个类在哪个dll 中的? 数据库名字 should not matter, as long as it existsopen a dos window, go to bin subdirectory, look for any new dll and runildasm yourdll.dll 怎么在提交表单时,执行AJAX的异步处理方法 如何隐藏一个js的引入 gridview 分页 高手请进 怎样区分中文汉字和日文汉字? 急急,明天要交差了 document.write的东西怎么通过程序取出其输出的内容呢 C#中new关键字得用法 求一段另存和打印的代码 vs 2005 和 vs2010 性能方面 任何用循环语句为Image控件赋值? FileInfo批量下载问题请教 如何确定多行TextBox的行数呀,多谢! recordset出错
IBuySpy.ProductDetails myProductDetails = (IBuySpy.ProductDetails)products.GetProductDetails(ProductID);
{}
我照 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;
}
是同一个类型的啊,这一句:
// 用存储过程的输出填充到 ProductDetails 结构
ProductDetails pd = new ProductDetails(); ...
return pd;
在调用前对变量productID强制类型转换为INT32 productID=Convert.Int32(productID)
还是一样的错误~哪位大哥能救救我啊?
2. the dll loaded at runtime is the old one
我有点疑惑的地方是,运行时,程序是如何判断哪个类在哪个dll 中的?