2 <MyMembers name="Class">
\r
4 <B>MySqlCommand</B> features the following methods for executing commands at a MySQL database:
\r
6 <listheader><term>Item</term><term>Description</term></listheader>
\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
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
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
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
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
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
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
52 myCommand.ExecuteNonQuery()
\r
53 myCommand.Connection.Close()
\r
57 public void InsertRow(string myConnectionString)
\r
59 // If the connection string is null, use a default.
\r
60 if(myConnectionString == "")
\r
62 myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass";
\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
78 <MyMembers name="ConnectionTimeout">
\r
79 <exception cref="System.ArgumentException">The value set is less than 0.</exception>
\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
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
96 public void CreateSqlConnection()
\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