我的代码如下所示,这个存储过程'get2Rows‘返回2行,我想获取第一行并获取列值,然后是第二行并获取列值。我需要如何迭代?
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....
}
};
}发布于 2012-05-23 00:31:27
while (reader.Read())//here i want to get the 1st row
{
//here i want to get the columns of the 1st row....
int firstColumn = Convert.ToInt32(dr[0]["intColumn"].ToString());
string secondColumn = dr[0]["stringColumn"].ToString();
// etc.
}您将获得这两行,因为您正在遍历它们。你想如何存储它们由你决定,也许是在一个集合中?
更多信息:http://www.csharp-station.com/Tutorial/AdoDotNet/lesson04
我的建议是,如果您使用的是DataReader,那么应该一次处理一行,因为这就是它的操作方式。如果您希望所有行都在内存中,则应该使用DataSet。
https://stackoverflow.com/questions/10706166
复制相似问题