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);
}
}

Wim SturkenboomRank #2,527 · 554 reputationPosted Dec 9, 2014, 11:03 PM EST
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.
David SmithRank #999 · 2K reputationPosted Dec 10, 2014, 3:19 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 10, 2014, 3:59 AM EST
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 SmithRank #999 · 2K reputationPosted Dec 10, 2014, 4:05 AM EST
public static int AddRowReturnIntPointer(ref DataTable datatable)
{
try
{
return 0;
}
catch (Exception ex)
{
throw new Exception("AddRowReturnIntPointer: \n" + ex.Message);
}
}
VulpesRank #55 · 29.2K reputationPosted Dec 10, 2014, 4:17 AM EST
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 SmithRank #999 · 2K reputationPosted Dec 10, 2014, 4:33 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 10, 2014, 4:34 AM EST
David SmithRank #999 · 2K reputationPosted Dec 10, 2014, 5:03 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 10, 2014, 5:52 AM EST
Anyway, if it's adding a new row and then returning the index, that's a straightforward matter:
As expected, the output is: