System.InvalidCastException assigning dataset values to a textbox in vb.net 2017

FRANCES MACKENZIE 1 Reputation point
2020-11-08T10:52:19.467+00:00

I've created a dataset using an Access database as the data source and then want to populate two text boxes using the dataset rows. The first textbox is populated fine but I'm getting an error on the second textbox. Both textboxes are identical and the dataset fields I'm using are identical. Can anybody help?

System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox'.

Developer technologies Visual Studio Debugging
{count} votes

1 answer

Sort by: Most helpful
  1. Xingyu Zhao-MSFT 5,381 Reputation points
    2020-11-09T07:56:23.927+00:00

    How is the question going?

    As DavidLowndes suggested, you can use following code to assign string to the textbox's text.

    TextBox1.Text = DataSet1.Tables("your table name").Rows(index1)(index2)   
    

    Or directly bind the textbox 'Text' property to table's column.

    38247-1.png

    Best Regards,
    Xingyu Zhao

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.