我想让数据显示在文本框中,但我收到了这个错误“无法转换类型的对象'System.String' 输入“System.Windows.Forms.TextBox”请帮助VB 2010无法将类型'System.String'的对象转换为键入'System.Windows.Forms.TextBox'
txtVendorFAX = daPo.Tables("vendor").Rows(i).Item(3)
我想让数据显示在文本框中,但我收到了这个错误“无法转换类型的对象'System.String' 输入“System.Windows.Forms.TextBox”请帮助VB 2010无法将类型'System.String'的对象转换为键入'System.Windows.Forms.TextBox'
txtVendorFAX = daPo.Tables("vendor").Rows(i).Item(3)
您可以将字符串只分配到的.Text
财产一个Textbox
。
到目前为止给出的答案不能使用Option Strict On编译。
你应该使用:
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3).ToString
你也应该确保你有选项严格已开启:http://www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html
试试这个:
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
使用文本框的.Text
财产使用下面的代码
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
一文本框是Textbox
,而不是一个字符串。这就是为什么你所得到的错误 Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox
这就是所谓的基本知识......每个人都必须开始我知道,但不是发布,下次做一些研究:http://bit.ly/1bMq5q6 –