0

行番号の並べ替えに問題があります。私のコードはこのように出力されます

(801;802;803;804;805;806;807;808-814(1);808-814(2);815;;;;;;;;;;;;;;;;;840) 

その区切り文字は840までループします。

Dim sqlline As DataTable = MyDB.ExecCommand("SELECT `Line Number` from `" + cboJob.Text + "` WHERE `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + "' ORDER BY `Line Number`", "wellsfargo").Tables(0)
                    For q As Integer = 0 To sqlline.Rows.Count - 1
                        If sqlline.Rows.Count <> 0 Then

                            If q = 0 Then
                                lNum = sqlline.Rows(q).Item(0).ToString
                            Else
                                lNum += IIf(dZ.Rows(q).Item(13).ToString <> "", ";" + sqlline.Rows(q).Item(0).ToString, ";")
                            End If
                            'lNum += IIf(sqlline.Rows(q).Item(0).ToString <> "", ";" + sqlline.Rows(q).Item(0).ToString, "")

                        End If
                    Next

しかし、私は私の出力がこのようになることを望んでいます。

(801;802;803;804;805;806;807;815;;;;;;;;;;;;;;;;;;;;;840;808-814(1);808-814(2))

したがって、すべての行番号が最後になります。

今..編集私は、単一の行番号の最後に空白の区切り文字を置くために、このコードを持っています:

  Dim sCont As String = ""
            If dZ.Rows.Count < 40 Then
                Dim iCont As Integer = 40 - dZ.Rows.Count
                For c As Integer = 0 To iCont - 1
                    If c = 0 Then
                        sCont = ";"
                    Else
                        sCont += ";"
                    End If
                Next
                'Loop then Concatinate strings for each field value.
            ElseIf dZ.Rows.Count = 40 Then
                'Loop as is...
            End If

            Dim sVal As String()
            If dZ.Rows.Count < 40 Then
                sVal = (OrgDocbeg + "■" + _
                                OrgDocend + "■" + _
                                BEGDOC + "■" + _
                                ENDDOC + "■" + _
                                LoanNum + "■" + _
                                PCount + "■" + _
                                Path + "■" + _
                                FNum + "■" + _
                                sDate + "■" + _
                                StrConv(LNF, VbStrConv.ProperCase) + "■" + _
                                lNum + sCont + "■" + _
                                sDesc + sCont + "■" + _
                                StrConv(Amount, VbStrConv.ProperCase).Replace("Poc", "POC").Replace(".00.00", "") + sCont + "■" + _
                                sPay.Replace("^", "").Replace(" Of ", " of ").Replace(" And ", " and ").Replace(" And/or", " and/or").Replace(" By ", " by ").Replace(" 2Nd ", " 2nd ").Replace(" 3Rd ", " 3rd ") + sCont + "■" + _
                                sBorrow.Replace("$.00", "$0.00") + sCont + "■" + _
                                sSell + sCont + "■" + _
                                ProsBor + sCont + "■" + _
                                ProSell + sCont).Split("■")

            Else
                sVal = (OrgDocbeg + "■" + _
                                OrgDocend + "■" + _
                                BEGDOC + "■" + _
                                ENDDOC + "■" + _
                                LoanNum + "■" + _
                                PCount + "■" + _
                                Path + "■" + _
                                FNum + "■" + _
                                sDate + "■" + _
                                StrConv(LNF, VbStrConv.ProperCase) + "■" + _
                                lNum + "■" + _
                                sDesc + "■" + _
                                sPay.Replace("^", "").Replace(" Of ", " of ").Replace(" And ", " and ").Replace(" And/or", " and/or").Replace(" By ", " by ").Replace(" 2Nd ", " 2nd ").Replace(" 3Rd ", " 3rd ") + "■" + _
                                StrConv(Amount, VbStrConv.ProperCase).Replace("Poc", "POC").Replace("$.", "$0.") + "■" + _
                                sBorrow.Replace("$.", "$0.") + "■" + _
                                sSell.Replace("$.", "$0.") + "■" + _
                                ProsBor.Replace("$.", "$0.") + "■" + _
                                ProSell.Replace("$.", "$0.")).Split("■")
            End If

しかし、私の出力は間違っています:

 801;802;803;804;;;;;;;;808 - 817(1);808 - 817(2);808 - 817(3);808 - 817(4);808 - 817(5);808 - 817(6);;;;;;;;;;;;;;;;;;;;;;;

行番号に範囲がある場合、出力は次のようになります(840までの区切り文字が必要です)

801;802;803;804;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;808 - 817(1);808 - 817(2);808 - 817(3);808 - 817(4);808 - 817(5);808 - 817(6)

しかし、範囲がない場合、正しい出力は次のようになります

801;802;803;804
4

2 に答える 2

1

ラインコードの長さが固定されている場合は、結果セットを長さに基づいて分割し、個別に並べ替えてから、次のように組み合わせることができますUNION ALL

Dim strQuery = "(SELECT `Line Number` FROM `" + cboJob.Text + _ 
"` WHERE LOCATE('-', line) = 0 AND `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + _
" ORDER BY `Line Number`) " + _ 
"UNION ALL " + _
"(SELECT `Line Number` FROM `" + cboJob.Text + _ 
"` WHERE LOCATE('-', line) > 0 AND `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + _
" ORDER BY `Line Number`)"

Dim sqlline As DataTable = MyDB.ExecCommand(strQuery, "wellsfargo").Tables(0)
于 2012-12-26T05:56:02.467 に答える
0

最後のコメントで指摘された問題に関して、これを解決する方法の1つは次のとおりです。

  1. COUNTを使用して範囲があるかどうかを確認します
  2. 範囲がある場合は、通常の行番号のみを取得し、文字列のギャップを埋める数値を入力します
  3. 範囲がある場合は、それらを取得して、範囲番号を使用して文字列を作成します
  4. 文字列を連結します

そのための部分的または疑似コードは次のとおりです。

'Retrieve a count of ranges in the resultset
'Replace objConn with your connection variable 
Dim strQuery As String = "SELECT COUNT(*) AS `RangesCount` FROM `" + cboJob.Text + _ 
"` WHERE LOCATE('-', line) > 0 AND `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + _
" GROUP BY `Line Number`"
Dim cmdQuery As New MySqlCommand(strQuery, objConn)
Dim intHasRanges As Integer = CInt(cmdQuery.ExecuteScalar())

'Retrieve just line numbers without ranges
'
Dim strQuery As String = "SELECT `Line Number` FROM `" + cboJob.Text + _ 
"` WHERE LOCATE('-', line) = 0 AND `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + _
" ORDER BY `Line Number`"
Dim sqlline As DataTable = MyDB.ExecCommand(strQuery, "wellsfargo").Tables(0)

'Do your For-Next loop here and populate your first part of your string strResult 
'knowing that if intHasRanges > 0 then we have ranges and we need to fill gaps between numbers
Dim strResult As String = ""
For ...
    ...
    strResult = ...
    ...
Next

'Retrieve ranges only if we have them
'
If intHasRanges > 0 Then
    Dim strQuery As String = "SELECT `Line Number` FROM `" + cboJob.Text + _ 
    "` WHERE LOCATE('-', line) > 0 AND `Orig Document Begin ID`='" + mData.Rows(z).Item(0).ToString.Trim + _
    " ORDER BY `Line Number`"
    Dim sqlline As DataTable = MyDB.ExecCommand(strQuery, "wellsfargo").Tables(0)

    'Do your For-Next loop to populate strRanges
    '
    Dim strRanges As String = ""
    For ...
        strRanges = ...
    Next

    If srtRange.Length > 0 Then
        strResult = strResult + strRanges
    End If
End If

'Do whatever you need to do with that string
于 2012-12-27T05:00:57.940 に答える