Dim cmd1 As New S QLCommand
cmd1.C
'Dim dt1 As DataTable
Dim bm As String
Dim bm2, bm3, bm4, bm5 As Integer
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "S elect DISTINCT 一级科目,二级科目,三级科目,四级科目,五级科目,收支类别 From {科目表} " '生成空表
dt = cmd.ExecuteReader() '记得将参数设置为True
Dim sts() As String = {"收入", "支出", "银行", "现金", "中转"}
If dt.DataRows.Count > 0 Then
For i As Integer = 0 To sts.Length - 1
Dim cmd0 As New SQLCommand
cmd0.C
Dim dt0 As DataTable
cmd0.CommandText = "S elect DISTINCT 一级科目,二级科目,三级科目,四级科目,五级科目,收支类别 From {科目表} Where 收支类别='" & sts(i) & "'" '生成表
dt0 = cmd0.ExecuteReader() '记得将参数设置为True
Dim s2s As List(Of String) = dt0.GetValues("二级科目", "二级科目 is not null")
For Each s2 As String In s2s
bm2 = bm2 + 1
Dim bm22 As String = Format(bm2, "000")
bm = i + 1 & bm22
cmd1.CommandText = "U PDATE {科目表2} SET 科目编码 ='" & bm & "',科目名称='" & s2 & "'"
cmd1.ExecuteNonQuery
Dim s3s As List(Of String) = dt0.GetValues("三级科目", "三级科目 is not null and 二级科目='" & s2 & "'")
For Each s3 As String In s3s
bm3 = bm3 + 1
Dim bm32 As String = Format(bm3, "000")'
bm = i + 1 & bm22 & bm32
cmd1.CommandText = "U PDATE {科目表2} SET 科目编码 ='" & bm & "',科目名称='" & s3 & "'"
cmd1.ExecuteNonQuery()
Dim s4s As List(Of String) = dt0.GetValues("四级科目", "四级科目 is not null and 二级科目='" & s2 & "'and 三级科目='" & s3 & "'")
For Each s4 As String In s4s
bm4 = bm4 + 1
Dim bm42 As String = Format(bm4, "000")'
bm = i + 1 & bm22 & bm32 & bm42
cmd1.CommandText = "U PDATE {科目表2} SET 科目编码 ='" & bm & "',科目名称='" & s4 & "'"
cmd1.ExecuteNonQuery()
Dim s5s As List(Of String) = dt0.GetValues("五级科目", "五级科目 is not null and 二级科目='" & s2 & "'and 三级科目='" & s3 & "'and 四级科目='" & s4 & "'")
For Each s5 As String In s5s
bm5 = bm5 + 1
Dim bm52 As String = Format(bm5, "000")'
bm = i + 1 & bm22 & bm32 & bm42 & bm52
cmd1.CommandText = "U PDATE {科目表2} SET 科目编码 ='" & bm & "',科目名称='" & s5 & "'"
cmd1.ExecuteNonQuery()
Next
bm5 = 0
Next
bm4 = 0
Next
bm3 = 0
Next
bm2 = 0
Next
End If
MessageBox.Show("数据输入完成")
我改了,还是没有输入 为什么,原科目表2为空表,科目表有数据,这样就不能科目表的数据添加到科目表2吗,只能修改吗
[此贴子已经被作者于2022/9/16 18:34:49编辑过]