I need to use MySql inside of a C# application - so far, I am having mixed results.
I can connect and issue the commands just fine, however, I am having real issues processing the output and results.
I can't seem to find firm and good documentation. The only official documentation I can seem to find is here - http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqldatareader.html
My biggest problem is that I just can't understand the basics...
while (Reader.Read())
The documentation just doesn't really go in to any details on how this works.
After I have done the above, I have seen a few different examples, and I can pull the data in the following ways
Console.WriteLine(Reader[0] + " - " + Reader[1]);
or
for (int i = 0; i < Reader.FieldCount; i++)
Console.WriteLine(Reader.GetValue(i).ToString() + ",");
However, I can't seem to find documentation that covers either and do not fully understand what is happening.
At the moment, I do not want specific code examples, I would just ideally like a link to some solid and good documentation or (/preferably in addition) an explanation on what Reader.Read is doing and the two other code examples.
you can read the documentation of the .NET IDataReader and it's pretty much all you need to start.
you use code like the following:
Console.WriteLine(Reader[0] + " - " + Reader[1]);
if you already know that what you need is in the first and second column of the query and you use the for loop
approach if you want to show / use all columns without knowing how many columns you get from the query. Usually in a real world application you write queries and stored procedure which select only some fields (not use SELECT *...
) so you know exactly the position of which columns you are dealing with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With