Reputation: 1003
I want to Select Current Row Position in DataSet but without any loops, it's possible I know but i got stuck....
First I declare a DataTable and fill it with data:
DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];
And then there is a if loop in witch I have this code:
if (dr_art_line_2.Rows.Count > 0)
{
int ID_line = (int)ds.Tables["Line"].Select()[0]["Line_Id"];
int ID = (int)ds.Tables["QuantityInIssueUnit"].Select()[ID_line]["Line_Id"];
QuantityInIssueUnit_value = Convert.ToString(dr_art_line_2.Rows[ID] ["QuantityInIssueUnit_Text"]);
QuantityInIssueUnit_uom = Convert.ToString(dr_art_line_2.Rows[ID]["uom"]);
}
else
{
QuantityInIssueUnit_value = "";
QuantityInIssueUnit_uom = "";
}
I have problem here:
int ID_line = (int)ds.Tables["Line"].Select()[0]["Line_Id"];
int ID = (int)ds.Tables["QuantityInIssueUnit"].Select()[ID_line]["Line_Id"];
I want to select "Line ID", that's ok but ID_line has to increment by one on each iteration, is there a way to make some kind of select of something else?
Thanks!
Upvotes: 0
Views: 7928
Reputation: 1003
This is the stuff, IT WORKS!!!!
if (dr_art_line_2.Rows.Count > 0)
{
int ID_line = dr_art_line_1.Rows.IndexOf(dr_art_line);
//int ID_line = (int)ds.Tables["Line"].Select()[0]["Line_Id"];
int ID = (int)ds.Tables["QuantityInIssueUnit"].Select()[ID_line]["Line_Id"];
QuantityInIssueUnit_value = Convert.ToString(dr_art_line_2.Rows[ID]["QuantityInIssueUnit_Text"]);
QuantityInIssueUnit_uom = Convert.ToString(dr_art_line_2.Rows[ID]["uom"]);
}
else
{
QuantityInIssueUnit_value = "";
QuantityInIssueUnit_uom = "";
}
Upvotes: 1
Reputation: 1056
The CurrentRow (data cursor) is a concept for connected data sources (VB6 ActiveX ADO.) When you move, update or delete the CurrentRow, the changes are written back to the data source.
A DataTable or DataSet is a collection of rows returned from a DISconnected data source (ADO.NET.)
If you want the "current row" of a DataTable, you could create a wrapper class for the DataTable and add an iCurrentRow property. As you "navigate" thru the rows, you would need to update this member variable (in MoveFirst. MoveLast, MoveNext and MovePrev methods you provide in this wrapper class.)
Refer to: http://support.microsoft.com/kb/310372 for other alternatives.
If you want the row number of a DataGrid see this article: http://www.codeproject.com/Articles/9601/Obtaining-Current-DataTable-Row-for-a-DataGrid
Upvotes: 1