c# mysql 数组,从MySql到C#数组的查询

Hello people.

I have a good question. In almost every part of Internet I see methods that help to save Mysql queries into an array using php, BUT I need to do it using C#.:suss:

I found this: http://stackoverflow.com/questions/4440378?tab=newest#tab-top[^]

and I have the same method using ExecuteReader but the answer didn''t help me at all :thumbsdown:, I still have the following problem:

I have 2 columns in mysql: initialdate, finaldate. With 3 numbers of rows as an example.

I execute the following query: select * from datetable

And then, when I want to read the received information with my C# app:myReader = myCommand.ExecuteReader();

while(myReader.Read())

{

//it recovers the first value of first row

Console.WriteLine(myReader.GetString(0));

//it recovers the second value of first row

Console.WriteLine(myReader.GetString(1));

//I can't recover the rest of info. If I execute the next line

//an error of 'index value out of range' or something similar

Console.WriteLine(myReader.GetString(2));

//this part works in the same way. I use it.

//(and the problem is still the same too):

Console.WriteLine(myReader[0]);

//works good

Console.WriteLine(myReader[1]);

//ouch:

Console.WriteLine(myReader[2]);

}

}

I tried to recover the info using something like:

Console.WriteLine(myReader.GetString(0,0));

//or:

Console.WriteLine(myReader[0,0]);

Console.WriteLine(myReader[0][0]);

But it doesn''t work :((

How can I recover the rest of rows? HEEEELP! and Thanks!

解决方案

myReader.Readreads exactly one row and then you can access the columns

with myReader[0] and myReader[1] because there are only two columns you cant do myreader[2] as that would try to read the third columns which as you already stated doesn''t exist.

As long as there are rows left in your result the myReader.Read() (see your while statement) will return true. So in every execution of your loop you''re able to process exactly one line.

Hope that helps! :)

Best regards,

Manfred

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值