RIAS
asked on
Add row in datatable
Hello ,
How do I add the row to a datatable
How do I add the row to a datatable
For Each row As DataGridViewRow In Dg.Rows
If IsDBNull(Dg.Rows(row.Index).Cells(0).Value) = False AndAlso (Dg.Rows(row.Index).Cells(0).Value) = True Then
dt.Rows.Add(row.)----error
End If
Next
are both the datagridview and the datatable have exactly the same definitions (same columns)?
ASKER
Yes
ASKER
Dim dt As DataTable = DirectCast(Dg.DataSource, DataTable).Clone()
I would try this (not tested):
For Each row As DataRow In DirectCast(Dg.DataSource, DataTable).Rows
If IsDBNull(row(0).Value) = False AndAlso (row.(0).Value) = True Then
dt.Rows.Add(row)
End If
Next
what are you trying to do? Duplicate the rows?
ASKER
Yes duplicate the selected rows
ASKER
Eric,
Got this eror on your code
An unhandled exception of type 'System.MissingMemberExcep tion' occurred in Microsoft.VisualBasic.dll
Additional information: Public member 'Value' on type 'Boolean' not found.
Got this eror on your code
An unhandled exception of type 'System.MissingMemberExcep
Additional information: Public member 'Value' on type 'Boolean' not found.
ASKER
on this code:
If IsDBNull(row(0).Value) = False AndAlso (row(0).Value) = True Then
If IsDBNull(row(0).Value) = False AndAlso (row(0).Value) = True Then
try this:
If not IsDBNull(row(0)) AndAlso row(0) = True Then
ASKER
How can I add the clonerows to datable?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Eric,
Will try and get back
Will try and get back
ASKER
Eric,
Dim originalRow As DataRow = DirectCast(Dg.CurrentRow.D ataBoundIt em, DataRowView).Row
takes the row fronm the original datatable i.e datasource of the datagridview.But my datagridview is sorted and has datasource as dataview and not datatable.
How can i get the current row from dataview and not datatable.
Cheers
Dim originalRow As DataRow = DirectCast(Dg.CurrentRow.D
takes the row fronm the original datatable i.e datasource of the datagridview.But my datagridview is sorted and has datasource as dataview and not datatable.
How can i get the current row from dataview and not datatable.
Cheers
ASKER
Any suggestion on
dt.ImportRow(DirectCast(Dg .DataSourc e, DataTable).Rows(row.Index) )
to be dataview than datatable
dt.ImportRow(DirectCast(Dg
to be dataview than datatable
ASKER
Thanks Eric!
That would have been good to know to start with! You surely have a key in your fields, Search for that key instead of relying to the row index.
^
|
the . after row needs to be removed -- what was the exact error (just in case this was a typo pasting here).