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