vb.net - 如何从动态创建的文本框中将数据保存到数据库中
问题描述
我在 flowlayout 面板上动态创建了文本框。文本框可以是任意数字。我正在尝试将这些值(整数)从文本框中保存到数据库中。我花了一天的时间来实现这一点,顺便说一句,我是新手。请指导我如何实现这一目标。非常感谢。我尝试保存到 List(Of...) 集合中,但它只返回最后一个值。这就是我试图实现这一目标的方法。我在另一个名为 clsHelper 的类中声明了 List 类型的共享列表。
Private Sub saveIntoList(flp As FlowLayoutPanel)
clsHelper.list = New List(Of String)
For Each tb in flp.Controls
If TypeOf tb Is TextBox Then
txtNo = DirectCast(tb,TextBox)
If txtNo.Name = "txtNo" Then
clsHelper.list.Add(txtNo.Text)
End If
End If
Next
End Sub
解决方案
问题可能是这种If
说法。只有TextBox
名称"txtNo"
被添加到您的list
. TextBoxes
不添加其他名称不同的内容。删除 ,If
所有内容都TextBoxes
将添加到您的list
.
If txtNo.Name = "txtNo" Then
clsHelper.list.Add(txtNo.Text)
End If
如果TextBoxes
不是. FlowLayoutPanel
_FlowLayoutPanel
Private Sub saveIntoList(flp As FlowLayoutPanel)
clsHelper.list = New List(Of String)
_saveIntoList(flp)
End Sub
Private Sub _saveIntoList(control As Control)
If TypeOf control Is TextBox Then
clsHelper.list.Add(DirectCast(control, TextBox).Text)
Return
End If
For Each child As Control In control.Controls
_saveIntoList(child)
Next
End Sub
推荐阅读
- c# - C# interop word、cut 和 past works 在 Office 2016 上但不在 Office 2019 上
- arduino - 带 Arduino 的频闪仪
- sql-server - SQL 中 LAG 的替代函数
- python-3.x - 我正在尝试使用registration#搜索学生结果?帮助申请
- ansible - ansible 中关于通过 win_shell 执行脚本的奇怪行为
- python - python中单链表中的is_empty和is_empty()有什么区别?
- python - TypeError: call() got an unexpected keyword argument 'is_training'(试图将代码从 TF 1.1.0 转换为 2.2.0)
- javascript - HTML/JAVASCRIPT 我为井字游戏制作了一个棋盘。我怎样才能让这个 JavaScript 工作?
- sql - 如何将透视时间列格式化为 HH:MM
- java - 大型json(objs数组)Java InputStream的流式反序列化