I have code like below, this stored procedure ‘get2Rows’ returns 2 rows, i want to get the 1st row and get the column values and then the 2nd rows and get the column values. How do i need to iterate?
using (System.Data.Common.DbCommand dbCommand = DataAccess.Instance().Database.GetStoredProcCommand("get2Rows"))
{
using (IDataReader reader = DataAccess.Instance().Database.ExecuteReader(dbCommand))
{
while (reader.Read())//here i want to get the 1st row
{
//here i want to get the columns of the 1st row....
}
};
}
You’re getting both rows because you are looping through them. It’s up to you how you want to store them, maybe in a collection?
More info: http://www.csharp-station.com/Tutorial/AdoDotNet/lesson04
My advice would be to work with one row at a time if you are using a DataReader because that is how it operates. If you want all the rows in memory, you should use a DataSet instead.