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?:confused::confused::confused::confused:
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")
Re: adding text in the textbox dynamically in the database
Quote:
Originally Posted by
rex_amidst
Here is my code:
The name property of the textbox cant be change.
What is the name property of the texbox created during runtime?:confused::confused::confused::confused:
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)