add row DataTable

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
My problems is, let say:

I have 1 sql statement, after i loop it and get the data, my DataTable will have one records at row(0).

After 2nd times looping my sql statement, my 2nd data will replace the 1st time data at row(0).

How can it can let me add it add row(1).

Below is my code, Thanks

VB.NET:
For Each DR In fromRST.Rows
For i = 6 To fromRST.Columns.Count - 1
valueTXN = DR(6)
If valueTXN IsNot Nothing Then
StrSQL = "Select * from WTCOMMENT where uniqueId ='" & valueTXN & "'"
DS = New DataSet
pmCon.QueryMe(StrSQL, DS, "WTCOMMENT")
If DS.Tables("WTCOMMENT").Rows.Count <> 0 Then
Dim DTnewTxn As New DataTable
For j = 0 To fromRST.Rows.Count - 1
pmCon.QueryMe(StrSQL, DTnewTxn)
DTtxn.Rows.Add(DTnewTxn.Rows(j).ItemArray)
Next
End If
End If
Next i
Next
 
Last edited by a moderator:
So DTtxn is the datatable you are talking about? Where is it declared?

And I don't know if it's necessary but your 'for j=0...' loop should probably end with 'Next j' (not sure)
 
the above code just my draft only,i just want to loop the somethings like datarow, when i loop the row data, i dun wan replace the 1st row of data, should be insert in the 2nd row of data
 
That's why i think it's important to know where DTtxn is declared and if it is set to nothing somewhere in the code.

Try to explain what you are trying to do in words instead of code, it might be clearer because i don't understand your code.
 
okay, i explain in words.actually this sql statement StrSQL = "Select * from WTCOMMENT where uniqueId ='" & valueTXN & "'" will return more than 1 data/records, like picture below:
dtrr6.jpg
So, I need to loop the sql statemet and get the each value of "valueTXN"; and retrieve the data like sql statement what i write as above. For example: like the picture above i highlighted column.
 
The image represents the contents of FromRST, i believe?

Try this:

VB.NET:
For Each DR In fromrst.Rows
     If DR.Item(6) IsNot Nothing Then
             valueTXN = DR.Item(6)
             StrSQL = "Select * from WTCOMMENT where uniqueId ='" & valueTXN & "'"
             DS = New DataSet
             pmCon.QueryMe(StrSQL, DS, "WTCOMMENT")
             If DS.Tables("WTCOMMENT").Rows.Count <> 0 Then
                    Dim DTnewTxn As New DataTable
                    pmCon.QueryMe(StrSQL, DTnewTxn)
                    DTtxn.Rows.Add(DTnewTxn.Rows(0).ItemArray)
             End If
      End If
Next

In each row of FromRST you check what's in column 6 and use that to look up the data you want in WTCOMMENT.
That data will be added to DTtxn.
 
Back
Top