MySQL Connector/Net |
MySqlCommand..::.Parameters Property |
MySqlCommand Class Example See Also Send Feedback |
Get the MySqlParameterCollection
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
public MySqlParameterCollection Parameters { get; } |
Visual Basic (Declaration) |
---|
Public ReadOnly Property Parameters As MySqlParameterCollection |
Visual C++ |
---|
public: property MySqlParameterCollection^ Parameters { MySqlParameterCollection^ get (); } |
Field Value
The parameters of the SQL statement or stored procedure. The default is an empty collection.Remarks
Connector/Net does not support unnamed parameters. Every parameter added to the collection must
have an associated name.
Examples
The following example creates a MySqlCommand and displays its parameters.
To accomplish this, the method is passed a MySqlConnection, a query string
that is a SQL SELECT statement, and an array of MySqlParameter objects.
CopyVB.NET
Public Sub CreateMySqlCommand(myConnection As MySqlConnection, _ mySelectQuery As String, myParamArray() As MySqlParameter) Dim myCommand As New MySqlCommand(mySelectQuery, myConnection) myCommand.CommandText = "SELECT id, name FROM mytable WHERE age=@age" myCommand.UpdatedRowSource = UpdateRowSource.Both myCommand.Parameters.Add(myParamArray) Dim j As Integer For j = 0 To myCommand.Parameters.Count - 1 myCommand.Parameters.Add(myParamArray(j)) Next j Dim myMessage As String = "" Dim i As Integer For i = 0 To myCommand.Parameters.Count - 1 myMessage += myCommand.Parameters(i).ToString() & ControlChars.Cr Next i Console.WriteLine(myMessage) End Sub
CopyC#
public void CreateMySqlCommand(MySqlConnection myConnection, string mySelectQuery, MySqlParameter[] myParamArray) { MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection); myCommand.CommandText = "SELECT id, name FROM mytable WHERE age=@age"; myCommand.Parameters.Add(myParamArray); for (int j=0; j<myParamArray.Length; j++) { myCommand.Parameters.Add(myParamArray[j]) ; } string myMessage = ""; for (int i = 0; i < myCommand.Parameters.Count; i++) { myMessage += myCommand.Parameters[i].ToString() + "\n"; } MessageBox.Show(myMessage); }