각 루프를 통해 매번 문자열 끝에 추가하는 내 gridview에 문제가 있습니다. 루프를 다시 통과하기 전에 추가를 제거하려고 시도하지만 (아래 코드에서 볼 수 있음) 작동하지 않는 것 같습니다.
Private Sub LoadData()
conn = New SqlConnection(connectionString)
ds = New DataSet("Accounts")
da = New SqlDataAdapter("SELECT [branch], [no] , [surname], [name], [type], [sub], [totalAmount], loc, locstatus, HoldCalc, odTimes " & _
"FROM [DmdOD]", conn)
conn.Open()
da.FillSchema(ds, SchemaType.Source, "Accounts")
da.Fill(ds, "Accounts")
conn.Close()
Dim loc As String
Dim hold As String
Dim holdString As String
Dim odString As String
Dim tblAccounts As DataTable
tblAccounts = ds.Tables("Accounts")
'Clone table in order to manipulate data
Dim dtClone As DataTable = tblAccounts.Clone()
dtClone.Columns("loc").DataType = System.Type.GetType("System.String")
dtClone.Columns("odtimes").DataType = System.Type.GetType("System.String")
dtClone.Columns("HoldCalc").DataType = System.Type.GetType("System.String")
'Perform logic on fields before binding to gridview
tblAccounts = DeleteDuplicateFromDataTable(tblAccounts, "no")
For Each dr As DataRow In tblAccounts.Rows
dtClone.ImportRow(dr)
For Each drClone As DataRow In dtClone.Rows
loc = drClone.Item("loc")
odString = drClone.Item("odtimes")
hold = drClone.Item("HoldCalc")
If loc = "0.0000" Then
loc = " "
drClone.Item("loc") = loc
End If
'hold = CType(drClone.Item("HoldCalc"), Decimal)
holdString = hold
If loc <> "0.0000" AndAlso holdString < "0.0000" Then
holdString &= " EX"
drClone.Item("HoldCalc") = holdString
ElseIf loc = "0.000" AndAlso hold < 0 Then
holdString &= " OD"
drClone.Item("HoldCalc") = holdString
Else
holdString = ""
drClone.Item("HoldCalc") = holdString
End If
If odString = "0" Then
odString = ""
drClone.Item("odtimes") = odString
End If
If holdString.Length > 2 AndAlso (holdString.Contains(" EX EX") OrElse holdString.Contains(" OD OD")) Then
drClone.Item("HoldCalc") = holdString.Substring(0, holdString.Length - 2)
End If
Next
Next
dtClone.AcceptChanges()
GVAccounts.DataSource = dtClone
GVAccounts.DataBind()
End Sub
루프를 통과 할 때마다 문자열 끝에 추가하고 조건이 충족되면 If 문에 들어오지 만 여전히 잘못된 출력으로 끝납니다. 내가 원하는 출력은 가격이 지나면 EX 나 OD 만 있어야하는데 그 대신 끝에 EX를 여러 번 출력하고 싶지 않아요 .... 그게 말이 되길 바랍니다.
어쨌든 나는이 문제를 해결하는 방법에 대해 당황스럽고 Google은 이것에 대해 도움이되지 않았습니다. 어떤 도움을 주시면 감사하겠습니다.
클론의 행을 여러 번 반복하기 때문에 여러 번 추가된다는 것은 많은 의미가 있습니다.
당신이에서 행을 추가 한 후 tblAccounts
까지 dtClone
의 모든 행 통해 루프 dtClone
및 새 행에 작업을 수행하고 모든 사람이 전에, 당신이 여러 번 추가되는 문자열로 끝나는 것을 정상입니다 그래서.
에서 행을 복제하고 tblAccounts
처리 한 다음 추가 하지 않는 이유는 무엇 dtClone
입니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다