我如何通过循环排在C#中的数据读取器?

编程入门 行业动态 更新时间:2024-10-23 17:27:01
本文介绍了我如何通过循环排在C#中的数据读取器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我可以使用而(dr.Read()){...} 但环在我的表中的每个领域,我想要检索的所有值从第一行,然后第二...等

I know I can use while(dr.Read()){...} but that loops every field on my table, I want to retrieve all the values from the first row, and then second... and so on.

让我们说我有一个表是这样的:

Let's say I have a table like this:

ID--------------Value1--------------Value2------------------Value3 1 hello hello2 hello3 2 hi1 hi2 hi3

首先我想要得到的,你好, hello2 和 hello3 ,然后去第二排,并得到所有的值。

first I want to get, hello, hello2 and hello3 and then go to the second row and get all the values.

有没有办法来实现这一目标?我希望有人明白我的意思。

Is there a way to achieve this? I hope somebody understand what I mean.

我很抱歉,这是现在解决了。我只是没有合适的编码...

并耶SqlDataReader.Read()方法做的事情是应该做的,又错误是我的。

推荐答案

就是这样的的DataReader 的作品,它的设计来读取数据库行一次。

That's the way the DataReader works, it's designed to read the database rows one at a time.

while(reader.Read()) { var value1 = reader.GetValue(0); // On first iteration will be hello var value2 = reader.GetValue(1); // On first iteration will be hello2 var value3 = reader.GetValue(2); // On first iteration will be hello3 }

更多推荐

我如何通过循环排在C#中的数据读取器?

本文发布于:2023-10-26 09:40:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529786.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:排在   读取器   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!