What would be the logic to add row , return row int pointer below:
public static int AddRowReturnIntPointer(ref DataTable datatable)
{
try
{
return 0;
}
catch (Exception ex)
{
throw new Exception("AddRowReturnIntPointer: \n" + ex.Message);
}
}
{
try
{
return 0;
}
catch (Exception ex)
{
throw new Exception("AddRowReturnIntPointer: \n" + ex.Message);
}
}
VulpesPosted Dec 10, 2014, 10:52 AM
Anyway, if it's adding a new row and then returning the index, that's a straightforward matter:
As expected, the output is:
David SmithPosted Dec 10, 2014, 10:03 AM
VulpesPosted Dec 10, 2014, 9:34 AM
David SmithPosted Dec 10, 2014, 9:33 AM
VulpesPosted Dec 10, 2014, 9:17 AM
The output is :
So although the DataView has been sorted, the DataTable hasn't and the last record added (namely with Value = 2m) has an index of 1.
BTW, no need to use a reference parameter for the DataTable as you're not assigning a new object to it.
David SmithPosted Dec 10, 2014, 9:05 AM
public static int AddRowReturnIntPointer(ref DataTable datatable)
{
try
{
return 0;
}
catch (Exception ex)
{
throw new Exception("AddRowReturnIntPointer: \n" + ex.Message);
}
}
VulpesPosted Dec 10, 2014, 8:59 AM
So, unless you've called ToTable() on the DataView and assigned it back to the same variable, datatable.Rows.Count - 1 should get the index of the last row added to the DataTable as Wim said initially.
David SmithPosted Dec 10, 2014, 8:19 AM
Wim SturkenboomPosted Dec 10, 2014, 4:03 AM
As rows are added (to my knowledge) at the end, it could be a simple matter of returning datatable.Rows.Count -1 .
This assumes that there is no filtering / sorting done.