MySql Documentation MySqlDataReader?

I need to use MySql inside a C # application. So far I have mixed results.

I can connect and issue commands very well, but I am having real problems processing results and results.

I can not find solid and good documentation. The only official documentation I can 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 figure out the basics ...

while (Reader.Read()) 

There is simply no detailed information in the documentation about how this works.

After I did this, I saw several 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, it seems that I cannot find documentation that covers and does not fully understand what is happening.

At the moment I do not want to use specific code examples, I would ideally like to get a link to some solid and good documentation or (preferably, additionally) an explanation of what Reader.Read does, and two other code examples.

+4
source share
5 answers

you can read the .NET IDataReader documentation, and that's almost all you need to get started.

you use the following code:

 Console.WriteLine(Reader[0] + " - " + Reader[1]); 

if you already know what you need in the first and second columns of the query, and you use the for loop approach, if you want to show / use all columns, not knowing how many columns you will get from the query. Typically, in a real-world application, you write queries and a stored procedure that select only certain fields (do not use SELECT *... ) so that you know exactly the position of the columns you are dealing with.

+5
source

There is simply no detailed information in the documentation about how this works.

Beginner hint:

DataReader implements IDataReader, which is fully documented in the .NET job.

while (Reader.Read ())

Reads the next line, returning true if possible, false if not (end of data).

+3
source

You can find answers in more general Data Retrieval with DataReader

+1
source

I'm not sure what your problem is. The while (Reader.Read ()) code only works with a loop as long as there is another entry in your Reader object. The list of documentation that you list gives you everything you need to know. What do you really think is missing?

Have you looked at Visual Studio for help with DataReaders and how they work? http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.100%29.aspx

+1
source

There is a MySql Connector help file, a .chm file that is installed as part of the installation for MySql.Net Connector if you select the option that is selected by default.

On my workstation running Windows 7 64 Bit, with MySQL Connector Net 6.4.4 installed, the help file is in the following directory, there should also be a menu item "No" "MySql" → "MySQL Connector Net 6.4.4".

 C:\Program Files (x86)\MySQL\MySQL Connector Net 6.4.4\Documentation 

For samples, you can pretty much use any of the IDataReader examples and replace IDataReader with MySqlDatareader.

+1
source

Source: https://habr.com/ru/post/1396052/


All Articles