如何将文本框值与其数据库字段ID相关联 [英] how to link textbox value with its database field id

查看:197
本文介绍了如何将文本框值与其数据库字段ID相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过其数据库字段存储文本框值。我有一个带有学号的组合框,当选中时 - 将所选学生的走廊名称和居住名称加载到文本框中。


当我调用插入方法时




I am trying to store the textbox value by its database field.. I have a combo box with student numbers that, when selected-loads the corridor name and residence name of that selected student into text boxes.

when i call the insert method

bo.AddEquipmentToStoreRoom(Convert.ToDateTime(lblDate.Text), Convert.ToDateTime(lblTime.Text), option1, txtStoreBarcode.Text, Convert.ToInt32(txtCorridorName.Text), Convert.ToString(cmbStudentNumber.SelectedValue), Convert.ToInt32(cmbDescription.SelectedValue));





它会返回错误消息输入字符串格式不正确...请帮助。谢谢。



it returns an error message saying "input string was not in a correct format"... Please help. Thanks.

推荐答案

当遇到这样的问题时,调试器可能是你手上最好的工具。



1)在抛出异常的句子放置一个断点。

2)让代码运行直到你的断点被击中。

3)使用快速监视调试视图来评估句子中涉及的每个表达式,

4)确定失败的代码片段后,更正它

5)再次测试代码如果需要,可以从步骤2重复。



在您的情况下,问题肯定是由于某些格式错误的字符串作为参数传递给其中一个Convert方法调用引起的你的代码。你必须单独检查它们。



也许你应该考虑在我们的代码中添加某种输入验证机制。
When facing problems like this, the debugger is probably the best tool you'll have at your hands.

1) Put one breakpoint at the sentence where the exception is thrown.
2) Let the code run until your breakpoint is hit.
3) Use the quick watch debug view to evaluate each expression involved in the sentence,
4) After determining the piece of code that fails, correct it
5) Test the code again and repeat from step 2) if needed.

In your case, most surely the problem is caused by some malformed string passed as parameter to one of the Convert method calls in your code. You'll have to check them all individually.

Perhaps you should consider adding some sort of input validation mechanism in our code.


这篇关于如何将文本框值与其数据库字段ID相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆