简体   繁体   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)

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.

相关问题 无法转换类型为'System.Windows.Forms.Button'的对象来键入>'System.Windows.Forms.TextBox' - Unable to cast object of type 'System.Windows.Forms.Button' to type > 'System.Windows.Forms.TextBox' 类型'String'的值不能转换为'System.Windows.Forms.Textbox'? - Value of type 'String' cannot be converted to 'System.Windows.Forms.Textbox'? '无法将'System.String'类型的对象转换为'System.Array'类型。' VB.net - 'Unable to cast object of type 'System.String' to type 'System.Array'.' vb.net 无法在 VB.NET 中将“System.String”类型的对象转换为“System.Data.DataTable”类型 - Unable to cast object of type 'System.String' to type 'System.Data.DataTable' in VB.NET 无法将类型为“ WhereArrayIterator`1 [System.String]”的对象转换为类型为“ System.String []”的对象 - Unable to cast object of type 'WhereArrayIterator`1[System.String]' to type 'System.String[]' 无法将类型为“ WhereSelectArrayIterator`2 [System.String,System.Byte]”的对象强制转换为“ System.Byte []”。 Vb.net - Unable to cast object of type 'WhereSelectArrayIterator`2[System.String,System.Byte]' to type 'System.Byte[]'. Vb.net 附加信息:无法将“System.Int32”类型的对象转换为“System.String”类型。 - VB.NET - Additional information: Unable to cast object of type 'System.Int32' to type 'System.String'. - VB.NET asp.net无法使用VB将类型为“ System.String”的对象转换为类型为“ System.Data.DataTable” - asp.net Unable to cast object of type 'System.String' to type 'System.Data.DataTable' Using VB VB.NET:无法将“System.Windows.Forms.MouseEventArgs”类型的对象转换为“System.Windows.Forms.KeyPressEventArgs”类型。 - VB.NET: Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'.' 无法将类型为system.string的对象转换为类型为system.io.fileinfo的对象 - unable to cast object of type system.string to type system.io.fileinfo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM