从组合框中插入选定的值(tinyint值)C# [英] Insert a selected value from a combo-box (tinyint value) C#
本文介绍了从组合框中插入选定的值(tinyint值)C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从组合框中插入选定的值(Win表单)
我有两个使用不同数据类型的组合框(Int和tinyint)
数据类型int正在工作
什么我试过了:
I'm trying to insert a selected value from a combo-box (Win forms)
I have two combo boxes that use different data type (Int and tinyint)
Data Type int is working
What I have tried:
For INT code is working
<pre>eventInfo.PersonDetailModuleID = Convert.ToInt32(cboPersonDetailModule.SelectedValue.ToString())
TinyInt代码无法使用
For TinyInt code is not working
eventInfo.ChildPersonDetailModuleID = Convert.ToByte(cboPersonDetailModuleChild.SelectedValue.ToString())
DAL
DAL
parms[2] = new SqlParameter("@PersonDetailModuleID", SqlDbType.Int, 4,ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.PersonDetailModuleID);
parms[3] = new SqlParameter("@ChildPersonDetailModuleID", SqlDbType.TinyInt,1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.ChildPersonDetailModuleID);
错误或警告:
Error OR Warning:
FormatException was unhandled
未处理的例外在mscorlib.dll中输入'System.FormatException'
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Input string was not in a correct format
推荐答案
从调试器开始,查看SelectedValue中的内容。
文档 - Convert.ToByte Method(System)| Microsoft Docs [ ^ ] - 表示FormatException在包含非数字值而不是 - 或字符串为空时发生。所以从调试器开始,确切地检查你传递给Convert.ToByte的内容。
Start with the debugger, and look at what is in your SelectedValue.
The documentation - Convert.ToByte Method (System) | Microsoft Docs[^] - says that the FormatException occurs when it contains a non-numeric value otehr than '-', or when the string is empty. So start with the debugger and check exactly what you are passing to Convert.ToByte.
当我填充我的组合框时,感谢OriginalGriff我使用了来自组合框的错误的ValueMember primaryID
我使用
Thank you OriginalGriff when I populate my combo box I used a wrong ValueMember primaryID from the combobox that use INT
I used
cboPersonDetailModuleChild.ValueMember = "PersonDetailModuleID";<pre>
而不是
cboPersonDetailModuleChild.ValueMember = "ChildPersonDetailModuleID";
这篇关于从组合框中插入选定的值(tinyint值)C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文