有这样一个表,想在输入查询条件身份证号时,动态1和动态2的label控件显示对应的字段名称,textbox1t和textbox2控件显示对应的字段数据
此主题相关图片如下:123.png
达到这种效果
此主题相关图片如下:1234.png
[此贴子已经被作者于2024/6/22 8:26:37编辑过]
比如说我输入吴小五的身份证号,根据身份证号遍历查询字段数据是否为空?如果字段数据为空就不显示,如果字段数据不为空就显示。
Dim dr As DataRow
dr = DataTables("某表").Find("身份证号='" & e.form.controls("条件").text & "'")
If dr IsNot Nothing Then '如果找到的话
dim i as integer = 1
for each dc as datacol in DataTables("某表").datacols
if dr.isnull(dc.name) = false
e.form.controls("动态" & i).text = dc.name
e.form.controls("textbox" & i).text = dr(dc.name)
end if
next
End If
窗体中没有表控件,是通过后台数据查询的表,提示没有dt的表
Dim cmd As New SQLCommand
cmd.C
Dim str As String = e.Form.Controls("sfz").text
Dim dt As DataTable
dt = cmd.ExecuteReader()
Dim dr As DataRow
dr = DataTables(dt).Find("身份证号='" & e.form.controls("sfz").text & "'")
If dr IsNot Nothing Then '如果找到的话
Dim i As Integer = 1
For Each dc As DataCol In DataTables(dt).datacols
If dr.isnull(dc.name) = False Then
e.form.controls("动态" & i).text = dc.name
e.form.controls("textbox" & i).text = dr(dc.name)
End If
Next
End If
dr = DataTables(dt).Find("身份证号='" & e.form.controls("sfz").text & "'")改为
dr = dt.Find("身份证号='" & e.form.controls("sfz").text & "'")
唉
For Each dc As DataCol In dt.datacols