Results 1 to 3 of 3

Thread: adding text in the textbox dynamically in the database

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    12

    Unhappy adding text in the textbox dynamically in the database

    Here is my code:
    Private Sub Add_Click

    Dim tbox As New TextBox
    tbox.Location = New Point(12, 244)
    tbox.Size = New Size(100, 20)
    Me.Controls.Add(tbox)

    End Sub

    ********
    I added a textbox dynamically during runtime. How will I add the text in the textbox to my database? The name property of the textbox cant be change.
    What is the name property of the texbox created during runtime?

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: adding text in the textbox dynamically in the database

    DataBind to the field you want. The example below Data Binds the First Name field in the DataTable to your TextBox. Navigation can be done say using a BindingSource to iterate thru the rows or if the DataTable is the source of say a DataGridView which would traverse the rows in the table.

    Code:
            Dim Table As New DataTable
            With Table.Columns
                .AddRange(New DataColumn() _
                   { _
                      New DataColumn("ID", GetType(System.String)), _
                      New DataColumn("FirstName", GetType(System.String)), _
                      New DataColumn("LastName", GetType(System.String)) _
                   } _
                )
            End With
    
            Table.Rows.Add(New Object() {"100", "Kevin", "Gallagher"})
    
            Dim tbox As New TextBox
            tbox.Location = New Point(12, 244)
            tbox.Size = New Size(100, 20)
            Me.Controls.Add(tbox)
            tbox.DataBindings.Add("Text", Table, "FirstName")

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: adding text in the textbox dynamically in the database

    Quote Originally Posted by rex_amidst View Post
    Here is my code:
    The name property of the textbox cant be change.
    What is the name property of the texbox created during runtime?
    Sure the name can be changed.

    Code:
            Dim tbox As New TextBox
            tbox.Location = New Point(0, 0)
            tbox.Size = New Size(100, 20)
            tbox.Name = "txtFirstName"
            Me.Controls.Add(tbox)
            Console.WriteLine("[{0}]", tbox.Name)
    Code:
    [txtFirstName]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width