R
Randy
I have a form with 36 text boxes on it. I have everything working for
the user to make changes to existing records or to add new ones. When
I come to the point of passing this data on to the data source, I'm
looking for an efficient way to do this. The only way that I know of
is a line-by-line procedure that passes each textbox to the
appropriate field in the data table one-by-one. Example:
Dim drNew As DataRow
drNew = dsMyDataSet.myTable.NewRow()
drNew.Item("Column1") = TextBox1.text
drNew.Item("Column2") = TextBox2.text
drNew.Item("Column3") = TextBox3.text
(etc, etc, through 36 text boxes)
dsMyDataSet.MyTable.Rows.Add(drNew)
taMyTableAdapter.Update(dsMyDataSet.MyTable)
dsMyDataSet.AcceptChanges()
I'd like to find a loop that would work something like this (more or
less):
Dim c As Control
Dim x as integer
For Each c In Me.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = DirectCast(c, TextBox)
x = +1
drNew.Item(x)=c.text
End If
Next
Anybody have any ideas?
Thanks,
Randy
the user to make changes to existing records or to add new ones. When
I come to the point of passing this data on to the data source, I'm
looking for an efficient way to do this. The only way that I know of
is a line-by-line procedure that passes each textbox to the
appropriate field in the data table one-by-one. Example:
Dim drNew As DataRow
drNew = dsMyDataSet.myTable.NewRow()
drNew.Item("Column1") = TextBox1.text
drNew.Item("Column2") = TextBox2.text
drNew.Item("Column3") = TextBox3.text
(etc, etc, through 36 text boxes)
dsMyDataSet.MyTable.Rows.Add(drNew)
taMyTableAdapter.Update(dsMyDataSet.MyTable)
dsMyDataSet.AcceptChanges()
I'd like to find a loop that would work something like this (more or
less):
Dim c As Control
Dim x as integer
For Each c In Me.Controls
If TypeOf c Is TextBox Then
Dim tb As TextBox = DirectCast(c, TextBox)
x = +1
drNew.Item(x)=c.text
End If
Next
Anybody have any ideas?
Thanks,
Randy