[英]VB 2010 Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox'
我想使数据出现在文本框中,但我收到此错误“无法将类型为'System.String'的对象转换为类型为'System.Windows.Forms.TextBox”,请帮助
txtVendorFAX = daPo.Tables("vendor").Rows(i).Item(3)
尝试以下方法:
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
Try this: 尝试这个:
txtVendorFAX.Text = Convert.ToString(daPo.Tables("vendor").Rows(i).Item(3)) txtVendorFAX.Text = Convert.ToString(daPo.Tables(“ vendor”)。Rows(i).Item(3))
You can only assign a string to the .Text
property of a Textbox
. 您只能将字符串分配给
Textbox
的.Text
属性。
The answers given so far do not compile with Option Strict On . 到目前为止给出的答案不能与Option Strict On一起编译 。
You should use: 您应该使用:
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3).ToString
You should also make sure you have Option Strict Turned On: http://www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html 您还应该确保已启用Option Strict: http : //www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html
use .Text
property of the textbox by using following code 通过使用以下代码,使用文本框的
.Text
属性
txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3)
a textbox is a Textbox
, not a string. 文本框是
Textbox
,而不是字符串。 This is why you are getting the error Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox
这就是为什么出现错误
Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.