How to Populate Textbox value to Textbox from unrelated table in VB.net ?

CWC
2 Min Read

How to Populate Textbox value to Textbox from unrelated table in VB.net ?

By using a DataSet and a DataTable object to organize your data from the database. So that DataTable may have many rows that were returned by the SQL query.

TextboxA and TextboxB are Windows Form TextBox objects placed on the form. Assume that tblWorkorder and tblChecklists are each a DataTable object that are assigned to the DataSet that hold the data from the database.

Because the two TextBox’s are on two different forms we need to save a reference to the second form so that when you want access to the form2 controls you use its reference and the control and property you want as shown below.

Public Class frmExample1

    '' Create a form level variable which make it available to all code in this Form
    Dim frm2 As frmExample2

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        
        '' Create the frmExample2 form and assign it to the class level variable and show the form
        frm2 = New Form2()
        frm2.Show()
        
        '' Now when you want to assign the value of TextBoxA to TextBoxB
        '' you can do this.
        frm2.TextBoxB.Text = TextBoxA.Text

    End Sub

End Class
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version