**** Merged from MCS ****
[mono-project.git] / mcs / class / ByteFX.Data / mysqlclient / docs / MySqlCommand.xml
blob69449609765e47042ec8663a80c0f140bcd3b5ad
1 <MyDocs>\r
2 <MyMembers name="Class">\r
3 <remarks>\r
4 <B>MySqlCommand</B> features the following methods for executing commands at a MySQL database:\r
5 <list type="table">\r
6         <listheader><term>Item</term><term>Description</term></listheader>\r
7         <item>\r
8                 <term><a href="ByteFX.Data.MySqlClient.MySqlCommand.ExecuteReader_overloads.html">ExecuteReader</a></term>\r
9                 <description>Executes commands that return rows.</description>\r
10         </item>\r
11         <item>\r
12                 <term><a href="ByteFX.Data.MySqlClient.MySqlCommand.ExecuteNonQuery.html">ExecuteNonQuery</a></term>\r
13                 <description>Executes commands such as SQL INSERT, DELETE, and UPDATE statements.</description>\r
14         </item>\r
15         <item>\r
16                 <term><a href="ByteFX.Data.MySqlClient.MySqlCommand.ExecuteScalar.html">ExecuteScalar</a></term>\r
17                 <description>Retrieves a single value (for example, an aggregate value) from a database.</description>\r
18         </item>\r
19 </list>\r
21 You can reset the <B>CommandText</B> property and reuse the <B>MySqlCommand</B> \r
22 object. However, you must close the <A \r
23 href="ByteFX.Data.MySqlClient.MySqlDataReader.html">MySqlDataReader</A> \r
24 before you can execute a new or previous command.\r
26 If a <A href="ByteFX.Data.MySqlClient.MySqlException.html">MySqlException</A> is \r
27 generated by the method executing a <B>MySqlCommand</B>, the <A \r
28 href="ByteFX.Data.MySqlClient.MySqlConnection.html">MySqlConnection</A> \r
29 remains open.  It is the responsibility of the programmer to close the connection.\r
30 </remarks>\r
32 <example>\r
33         The following example creates a <A href="frlrfsystemdatasqlclientsqlcommandclasstopic.htm">MySqlCommand</A> and \r
34         a <B>MySqlConnection</B>. The <B>MySqlConnection</B> is opened and set as the <A \r
35         href="frlrfsystemdatasqlclientsqlcommandclassconnectiontopic.htm">Connection</A> \r
36         for the <B>MySqlCommand</B>. The example then calls <A \r
37         href="frlrfsystemdatasqlclientsqlcommandclassexecutenonquerytopic.htm">ExecuteNonQuery</A>, \r
38         and closes the connection. To accomplish this, the <B>ExecuteNonQuery</B> is \r
39         passed a connection string and a query string that is a SQL INSERT \r
40         statement.\r
41         <code lang="Visual Basic">\r
42 Public Sub InsertRow(myConnectionString As String)\r
43         ' If the connection string is null, use a default.\r
44         If myConnectionString = "" Then\r
45                 myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass"\r
46         End If\r
47         Dim myConnection As New MySqlConnection(myConnectionString)\r
48         Dim myInsertQuery As String = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)"\r
49         Dim myCommand As New MySqlCommand(myInsertQuery)\r
50         myCommand.Connection = myConnection\r
51         myConnection.Open()\r
52         myCommand.ExecuteNonQuery()\r
53         myCommand.Connection.Close()\r
54 End Sub\r
55         </code>\r
56         <code lang="C#">\r
57 public void InsertRow(string myConnectionString) \r
58 {\r
59         // If the connection string is null, use a default.\r
60         if(myConnectionString == "") \r
61         {\r
62                 myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass";\r
63         }\r
64         MySqlConnection myConnection = new MySqlConnection(myConnectionString);\r
65         string myInsertQuery = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)";\r
66         MySqlCommand myCommand = new MySqlCommand(myInsertQuery);\r
67         myCommand.Connection = myConnection;\r
68         myConnection.Open();\r
69         myCommand.ExecuteNonQuery();\r
70         myCommand.Connection.Close();\r
71 }\r
72         </code>\r
73 </example>\r
76 </MyMembers>\r
78 <MyMembers name="ConnectionTimeout">\r
79         <exception cref="System.ArgumentException">The value set is less than 0.</exception>\r
80         <remarks>\r
81                 A value of 0 indicates no limit, and should be avoided in a \r
82                 <a href="ByteFX.Data.MySqlClient.MySqlConnection.ConnectionString.html">ConnectionString</a>\r
83                 because an attempt to connect will wait indefinitely.\r
84         </remarks>\r
85         <example>\r
86                 The following example creates a MySqlConnection\r
87                 and sets some of its properties in the connection string.\r
88                 <code lang="Visual Basic"><c>\r
89 Public Sub CreateSqlConnection()\r
90         Dim myConnection As New MySqlConnection()\r
91         myConnection.ConnectionString = "Persist Security Info=False;Username=user;Password=pass;database=test1;server=localhost;Connect Timeout=30"\r
92         myConnection.Open()\r
93 End Sub\r
94 </c></code>\r
95 <code lang="C#"><c>\r
96 public void CreateSqlConnection() \r
97 {\r
98         MySqlConnection myConnection = new MySqlConnection();\r
99         myConnection.ConnectionString = "Persist Security Info=False;Username=user;Password=pass;database=test1;server=localhost;Connect Timeout=30";\r
100         myConnection.Open();\r
102 </c></code>                             \r
103         </example>\r
104 </MyMembers>\r
106 </MyDocs>