繁体   English   中英

VB 2010无法将类型为“ System.String”的对象转换为类型为“ System.Windows.Forms.TextBox”

[英]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)

尝试这个:

txtVendorFAX.Text = Convert.ToString(daPo.Tables(“ vendor”)。Rows(i).Item(3))

您只能将字符串分配给Textbox.Text属性。

到目前为止给出的答案不能与Option Strict On一起编译

您应该使用:

txtVendorFAX.Text = daPo.Tables("vendor").Rows(i).Item(3).ToString

您还应该确保已启用Option Strict: http//www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html

通过使用以下代码,使用文本框的.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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM