Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Odatatable.rows.add(oDatatow)
Message
 
To
29/11/2012 13:16:07
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows NT
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01558336
Message ID:
01558455
Views:
58
Right Bonnie, I hate to admit it, but you are right. It works without the newrow. Thanks.

>Hey Marc,
>
>You don't need to do a .NewRow() before you do the .ImportRow().
>
>~~Bonnie
>
>
>>Hey Bonnie,
>>
>>You're right. You do need to issue a odt.newrow though before you odt.importrow, becasue the latter does not add rows.
>>
>>Thank you very much for your help.
>>
>>This seems to work as expected:
>>
>>
>>
>>    Public Sub testDatarows()
>>        Dim oDt As New DataTable
>>        oDt.Columns.Add("Field1", GetType(String))
>>        oDt.Columns.Add("Field2", GetType(String))
>>        oDt.Columns.Add("Field3", GetType(String))
>>        Dim odr As DataRow = oDt.NewRow
>>        odr("Field1") = "value 1"
>>        odr("Field2") = "value 2"
>>        odr("Field3") = "value 3"
>>        oDt.Rows.Add(odr)
>>        oDt.NewRow()
>>        oDt.ImportRow(odr)
>>        oDt(oDt.Rows.Count - 1)("Field3") = "value 4"
>>        For Each odr In oDt.Rows
>>            Debug.Print(odr("Field1") & "- " & odr("field2") & "-" & odr("Field3"))
>>        Next
>>    End Sub
>>
>>
>>>Hi Marc,
>>>
>>>The only thing that will allow you to do a similar kind of thing is the DataTable.ImportRow() method. Depending on how much you have to do this sort of thing, it may or may not be helpful. It would work something like this:
>>>
>>>
>>>    Public Sub testDatarows()
>>>        Dim oDt As New DataTable
>>>        oDt.Columns.Add("Field1", GetType(String))
>>>        oDt.Columns.Add("Field2", GetType(String))
>>>        oDt.Columns.Add("Field3", GetType(String))
>>>        Dim odr As DataRow = oDt.NewRow
>>>        odr("Field1") = "value 1"
>>>        odr("Field2") = "value 2"
>>>        odr("Field3") = "value 3"
>>>        oDt.Rows.Add(odr)
>>>
>>>        ' will add a new row
>>>        oDt.ImportRow(odr)
>>>        ' then change the newly added row
>>>        oDt.Rows(dt.Rows.Count-1).Items("Field3") = "value 4"
>>>
>>>        For Each odr In oDt.Rows
>>>            Debug.Print(odr("Field1") & "- " & odr("field2") & "-" & odr("Field3"))
>>>        Next
>>>    End Sub
>>>
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Consider the following code
>>>>
>>>>    Public Sub testDatarows()
>>>>        Dim oDt As New DataTable
>>>>        oDt.Columns.Add("Field1", GetType(String))
>>>>        oDt.Columns.Add("Field2", GetType(String))
>>>>        oDt.Columns.Add("Field3", GetType(String))
>>>>        Dim odr As DataRow = oDt.NewRow
>>>>        odr("Field1") = "value 1"
>>>>        odr("Field2") = "value 2"
>>>>        odr("Field3") = "value 3"
>>>>        oDt.Rows.Add(odr)
>>>>        odr("Field3") = "value 4"
>>>>        oDt.Rows.Add(odr)
>>>>        For Each odr In oDt.Rows
>>>>            Debug.Print(odr("Field1") & "- " & odr("field2") & "-" & odr("Field3"))
>>>>        Next
>>>>    End Sub
>>>>
>>>>It breaks at the second
>>>>
>>>>oDt.Rows.Add(odr)
>>>>
>>>>
>>>>throwing an exception : {"This row already belongs to this table."}
>>>>
>>>>Is there a way around this besides issuing a new
>>>>
>>>> odr = oDt.NewRow
>>>>
>>>>
>>>>and copy and pasting the assignments of the two first fields?

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Previous
Reply
Map
View

Click here to load this message in the networking platform