c# – 根据3层应用程序中的下拉列表填充文本框
我想根据我的下拉列表中的选择,使用值填充我的文本框.
DAL: public static string GetTicket(collection b) { try { string returnValue = string.Empty; DB = Connect(); DBCommand = connection.Procedure("getTicket"); DB.AddInParameter(DBCommand,"@SupportRef",DbType.String,b.SupportRef1); var myReader = DBCommand.ExecuteReader(); while (myReader.Read()) { returnValue = myReader.GetString(0); } return returnValue; } catch (Exception ex) { throw ex; } BLL: public string returnTicket(collection b) { try { string ticket = DAL.data.GetTicket(b); return ticket; } catch (Exception ex) { throw ex; } } PL: protected void ddl_Customers_SelectedIndexChanged(object sender,EventArgs e) { string selectedValue = ddl_Customers.SelectedValue.ToString(); //populate the text boxes txtSupportRef.Text = bobj.returnTicket(selectedValue); } 我的存储过程有一个名为SupportRef的变量,它需要一个值才能返回结果. 我收到以下错误: The best overloaded method match for 'BLL.business.returnTicket(DAL.collection)' has some invalid arguments 和 Argument 1: cannot convert from 'string' to 'DAL.collection' 解决方法
简答
在表示层中,将字符串类型映射到DAL.collection类型. You can see this here. protected void ddl_Customers_SelectedIndexChanged(object sender,EventArgs e) { string selectedValue = ddl_Customers.SelectedValue.ToString(); // map the string to a DAL.collection var collection = new DAL.collection(); collection.SupportRef1 = selectedValue; //populate the text boxes txtSupportRef.Text = bobj.returnTicket(collection); } 说明 这两个错误都是编译错误.你可以看到recreation of them both in this fiddle. 错误1
编译器正在尝试找到一个名为BLL.business.returnTicket的方法,它接受一个参数.在它找到的匹配中,该方法采用单个DAL.collection参数.你传给它的是一个字符串,这是一个无效的参数,因为字符串不是DAL.collection. From MSDN:
错误2
由于BLL.business.returnTicket采用DAL.collection参数,因此编译器会尝试将字符串转换为DAL.collection.它失败,因为没有从字符串类型到DAL.collection类型的隐式转换. From MSDN:
该怎么办? 根据复杂程度,您可以采取一些方法. >在表示层中,将字符串类型映射到DAL.collection类型.推荐的. 推荐的事情要做 在表示层中,将字符串类型转换或映射到DAL.collection类型.这就是上面的简短回答. 或者,在业务层中,除现有方法外,还要创建新的returnTicket(string)方法重载.它看起来像这样. public string returnTicket(collection b) { // map the string to a DAL.collection var collection = new DAL.collection(); collection.SupportRef1 = selectedValue; // call the existing method that takes a DAL.collection returnTicket(b); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |