简体   繁体   中英

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))

You can only assign a string to the .Text property of a Textbox .

The answers given so far do not compile with 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

use .Text property of the textbox by using following code

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

a textbox is a Textbox , not a string. This is why you are getting the error Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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