user3302146
user3302146

Reputation: 335

VB 2010 Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox'

i wanted to make the data appear in the text box but i recived this error "Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox" please help

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

Upvotes: 0

Views: 6195

Answers (5)

Matt Wilko
Matt Wilko

Reputation: 27342

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

Upvotes: 0

Dhananjay Athare
Dhananjay Athare

Reputation: 1

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

Upvotes: 0

Aditi
Aditi

Reputation: 509

Try this:

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

Upvotes: 1

Walter
Walter

Reputation: 2560

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

Upvotes: 1

Steve
Steve

Reputation: 5545

Try this instead:

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

Upvotes: 2

Related Questions