**** Merged from MCS ****
[mono-project.git] / mcs / class / ByteFX.Data / mysqlclient / docs / MySqlDataReader.xml
blobb2f1f66a65c0bc7ab42a1e634bdd05eaefc3cbbc
1 <MyDocs>\r
2 <MyMembers name="Class">\r
3 <remarks>\r
4         <para>To create a <B>MySQLDataReader</B>, you must call the <see cref="MySqlCommand.ExecuteReader"/>\r
5         method of the <see cref="MySqlCommand"/> object, rather than directly using a constructor.\r
6         </para>\r
7         <para>While the <B>MySqlDataReader</B> is in use, the associated <see cref="MySqlConnection"/>\r
8          is busy serving the <B>MySqlDataReader</B>, and no other operations can be performed \r
9          on the <B>MySqlConnection</B> other than closing it. This is the case until the \r
10          <see cref="MySqlDataReader.Close"/> method of the <B>MySqlDataReader</B> is called. \r
11          </para>\r
12         <para>Changes made to a resultset by another process or thread while data is being \r
13         read may be visible to the user of the <B>MySqlDataReader</B>. However, the \r
14         precise behavior is timing dependent.\r
15         </para>\r
16         <para><see cref="MySqlDataReader.IsClosed"/> and <see cref="MySqlDataReader.RecordsAffected"/> \r
17         are the only properties that you can call after the <B>MySqlDataReader</B> is \r
18         closed. Though the <B>RecordsAffected</B> property may be accessed at any time \r
19         while the <B>MySqlDataReader</B> exists, always call <B>Close</B> before returning \r
20         the value of <B>RecordsAffected</B> to ensure an accurate return value.\r
21         </para>\r
22         <para>For optimal performance, <B>MySqlDataReader</B> avoids creating \r
23         unnecessary objects or making unnecessary copies of data. As a result, multiple calls \r
24         to methods such as <see cref="MySqlDataReader.GetValue"/> return a reference to the \r
25         same object. Use caution if you are modifying the underlying value of the objects \r
26         returned by methods such as <B>GetValue</B>.\r
27         </para>\r
28 </remarks>\r
30 <example>\r
31         The following example creates a <see cref="MySqlConnection"/>, \r
32         a <see cref="MySqlCommand"/>, and a <B>MySqlDataReader</B>. The example reads through \r
33         the data, writing it out to the console. Finally, the example closes the <B>MySqlDataReader</B>, then the \r
34         <B>MySqlConnection</B>.\r
35         <code lang="Visual Basic">\r
36 Public Sub ReadMyData(myConnString As String)\r
37     Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"\r
38     Dim myConnection As New MySqlConnection(myConnString)\r
39     Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)\r
40     myConnection.Open()\r
41     Dim myReader As MySqlDataReader\r
42     myReader = myCommand.ExecuteReader()\r
43     ' Always call Read before accessing data.\r
44     While myReader.Read()\r
45         Console.WriteLine((myReader.GetInt32(0) &amp; ", " &amp; myReader.GetString(1)))\r
46     End While\r
47     ' always call Close when done reading.\r
48     myReader.Close()\r
49     ' Close the connection when done with it.\r
50     myConnection.Close()\r
51 End Sub 'ReadMyData\r
52         </code>\r
53         <code lang="C#">\r
54 public void ReadMyData(string myConnString) {\r
55     string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";\r
56     MySqlConnection myConnection = new MySqlConnection(myConnString);\r
57     MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection);\r
58     myConnection.Open();\r
59     MySqlDataReader myReader;\r
60     myReader = myCommand.ExecuteReader();\r
61     // Always call Read before accessing data.\r
62     while (myReader.Read()) {\r
63        Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));\r
64     }\r
65     // always call Close when done reading.\r
66     myReader.Close();\r
67     // Close the connection when done with it.\r
68     myConnection.Close();\r
69  }\r
70         </code>\r
71 </example>\r
74 </MyMembers>\r
78 </MyDocs>