从 ADODB 记录集转换为 ADO.net 并且难以找出问题所在
Converting to ADO.net from ADODB recordset and having difficulty figuring out what the problem is
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
For x = 1 To rsSum.RecordCount
If rsSum.Fields("Species").Value = sSpecies Then
bFound = True
Exit For
End If
rsSum.MoveNext()
Next x
If bFound = False Then
rsSum.AddNew()
rsSum.Fields("SpeciesSort").Value = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
rsSum.Fields("Species").Value = sSpecies
End If
lFootage = cPrint.GetItemArrayFootage(iRow, True)
rsSum.Fields("MTDShipFootage").Value = rsSum.Fields("MTDShipFootage").Value + lFootage
rsSum.Update()
rsSum.MoveFirst()
Next iRow
End If
上面是旧代码,下面是我尝试过的许多事情之一,但我的索引出了问题并抛出索引 'whatever number' 不存在的错误。
Dim bFound As Boolean
Dim lFootage As Integer
Dim iRow As Short
Dim lPlcHoldr As Long
Dim y As Integer = -1
x = -1
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
Dim my_row As DataRow
For Each my_row In dtSum.Rows
If my_row("Species") = sSpecies Then
bFound = True
y += 1
Exit For
End If
x += 1
Next
'For x = 0 To dtSum.Rows.Count - 1
' If dtSum.Rows(x)("Species") = sSpecies Then
' bFound = True
' Exit For
' End If
'Next x
Dim r As DataRow = dtSum.NewRow
If bFound = False Then
'Dim r As DataRow = dtSum.NewRow
r("SpeciesSort") = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
r("Species") = sSpecies
r("DlyShipFootage") = lPlcHoldr
r("DlyRemanFootage") = lPlcHoldr
r("DlyClaimFootage") = lPlcHoldr
r("MTDShipFootage") = lPlcHoldr
r("MTDRemanFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
dtSum.Rows.Add(r)
End If
If bFound = True Then
x = y
lFootage = cPrint.GetItemArrayFootage(iRow, True)
dtSum.Rows(x)("MTDShipFootage") = dtSum.Rows(x)("MTDShipFootage") + lFootage
daSum.Update(ds, "tblTmpDlySum")
Debug.WriteLine(lFootage)
Else
x += 1
lFootage = cPrint.GetItemArrayFootage(iRow, True)
r("MTDShipFootage") = r("MTDShipFootage") + lFootage
Debug.WriteLine(lFootage)
End If
Next iRow
End If
谁能看出我哪里搞砸了?我确定它是我在其中添加的 x
and/or y
。我是 vb.net 的新手,并且一起编码,因为 2022 年 12 月我被派去帮助将我们所有的遗留应用程序从 vb6 转换为 .net,我认为我应该将所有内容更新为 ado.net 同时更新其他所有内容。然而,这部分对我来说有点复杂。任何方向将不胜感激。
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
For x = 0 To dtSum.Rows.Count - 1
If dtSum.Rows(x)("Species") = sSpecies Then
bFound = True
Exit For
End If
Next x
Dim r As DataRow = dtSum.NewRow
If bFound = False Then
'Dim r As DataRow = dtSum.NewRow
r("SpeciesSort") = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
r("Species") = sSpecies
r("DlyShipFootage") = lPlcHoldr
r("DlyRemanFootage") = lPlcHoldr
r("DlyClaimFootage") = lPlcHoldr
r("MTDShipFootage") = lPlcHoldr
r("MTDRemanFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
dtSum.Rows.Add(r)
End If
If bFound = True Then
lFootage = cPrint.GetItemArrayFootage(iRow, True)
dtSum.Rows(x)("MTDShipFootage") = dtSum.Rows(x)("MTDShipFootage") + lFootage
daSum.Update(ds, "tblTmpDlySum")
Debug.WriteLine(lFootage)
x = 0
Else
lFootage = cPrint.GetItemArrayFootage(iRow, True)
r("MTDShipFootage") = r("MTDShipFootage") + lFootage
Debug.WriteLine(lFootage)
x = 0
End If
Next iRow
End If
这就是它起作用的原因。谢谢你的帮助。我想有人和某个地方可以把事情说出来真的让我明白发生了什么。将 x 重置回 0 允许 for 循环从数据表的第一行开始。
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
For x = 1 To rsSum.RecordCount
If rsSum.Fields("Species").Value = sSpecies Then
bFound = True
Exit For
End If
rsSum.MoveNext()
Next x
If bFound = False Then
rsSum.AddNew()
rsSum.Fields("SpeciesSort").Value = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
rsSum.Fields("Species").Value = sSpecies
End If
lFootage = cPrint.GetItemArrayFootage(iRow, True)
rsSum.Fields("MTDShipFootage").Value = rsSum.Fields("MTDShipFootage").Value + lFootage
rsSum.Update()
rsSum.MoveFirst()
Next iRow
End If
上面是旧代码,下面是我尝试过的许多事情之一,但我的索引出了问题并抛出索引 'whatever number' 不存在的错误。
Dim bFound As Boolean
Dim lFootage As Integer
Dim iRow As Short
Dim lPlcHoldr As Long
Dim y As Integer = -1
x = -1
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
Dim my_row As DataRow
For Each my_row In dtSum.Rows
If my_row("Species") = sSpecies Then
bFound = True
y += 1
Exit For
End If
x += 1
Next
'For x = 0 To dtSum.Rows.Count - 1
' If dtSum.Rows(x)("Species") = sSpecies Then
' bFound = True
' Exit For
' End If
'Next x
Dim r As DataRow = dtSum.NewRow
If bFound = False Then
'Dim r As DataRow = dtSum.NewRow
r("SpeciesSort") = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
r("Species") = sSpecies
r("DlyShipFootage") = lPlcHoldr
r("DlyRemanFootage") = lPlcHoldr
r("DlyClaimFootage") = lPlcHoldr
r("MTDShipFootage") = lPlcHoldr
r("MTDRemanFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
dtSum.Rows.Add(r)
End If
If bFound = True Then
x = y
lFootage = cPrint.GetItemArrayFootage(iRow, True)
dtSum.Rows(x)("MTDShipFootage") = dtSum.Rows(x)("MTDShipFootage") + lFootage
daSum.Update(ds, "tblTmpDlySum")
Debug.WriteLine(lFootage)
Else
x += 1
lFootage = cPrint.GetItemArrayFootage(iRow, True)
r("MTDShipFootage") = r("MTDShipFootage") + lFootage
Debug.WriteLine(lFootage)
End If
Next iRow
End If
谁能看出我哪里搞砸了?我确定它是我在其中添加的 x
and/or y
。我是 vb.net 的新手,并且一起编码,因为 2022 年 12 月我被派去帮助将我们所有的遗留应用程序从 vb6 转换为 .net,我认为我应该将所有内容更新为 ado.net 同时更新其他所有内容。然而,这部分对我来说有点复杂。任何方向将不胜感激。
If gItemCnt > 0 Then
For iRow = 1 To gItemCnt
sSpecies = Mid(gItemArray(iRow), 15, 2)
bFound = False
For x = 0 To dtSum.Rows.Count - 1
If dtSum.Rows(x)("Species") = sSpecies Then
bFound = True
Exit For
End If
Next x
Dim r As DataRow = dtSum.NewRow
If bFound = False Then
'Dim r As DataRow = dtSum.NewRow
r("SpeciesSort") = GetDesc(gSpeciesCodes, sSpecies, 3, 1)
r("Species") = sSpecies
r("DlyShipFootage") = lPlcHoldr
r("DlyRemanFootage") = lPlcHoldr
r("DlyClaimFootage") = lPlcHoldr
r("MTDShipFootage") = lPlcHoldr
r("MTDRemanFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
r("MTDClaimFootage") = lPlcHoldr
dtSum.Rows.Add(r)
End If
If bFound = True Then
lFootage = cPrint.GetItemArrayFootage(iRow, True)
dtSum.Rows(x)("MTDShipFootage") = dtSum.Rows(x)("MTDShipFootage") + lFootage
daSum.Update(ds, "tblTmpDlySum")
Debug.WriteLine(lFootage)
x = 0
Else
lFootage = cPrint.GetItemArrayFootage(iRow, True)
r("MTDShipFootage") = r("MTDShipFootage") + lFootage
Debug.WriteLine(lFootage)
x = 0
End If
Next iRow
End If
这就是它起作用的原因。谢谢你的帮助。我想有人和某个地方可以把事情说出来真的让我明白发生了什么。将 x 重置回 0 允许 for 循环从数据表的第一行开始。