![](/img/trans.png)
[英]Unable to cast object of type 'System.Windows.Forms.Button' to type > '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.