'Declaration Public Shadows ReadOnly Property Parameters As MySqlParameterCollection
public new MySqlParameterCollection Parameters {get;}
'Declaration Public Shadows ReadOnly Property Parameters As MySqlParameterCollection
public new MySqlParameterCollection Parameters {get;}
dotConnect for MySQL supports named and unnamed parameters.
static void CreateCommand(MySqlConnection myConnection, string mySelectQuery, MySqlParameter[] myParamArray) { MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection); string myMessage = ""; for (int i = 0; i < myParamArray.Length; i++) { myCommand.Parameters.Add(myParamArray[i]); myMessage += myCommand.Parameters[i].ToString() + "\n"; } Console.Write(myMessage); try { myConnection.Open(); myCommand.ExecuteNonQuery(); } finally { myConnection.Close(); } } static void Main(string[] args) { MySqlParameter[] myParams = new MySqlParameter[] { new MySqlParameter("DeptNo", 10), new MySqlParameter("DName", "COUNTING") }; MySqlConnection myConnection1 = new MySqlConnection( "User Id=root;Host=localhost;Database=Test;"); CreateCommand(myConnection1,"UPDATE Test.Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams); }
Public Sub CreateCommand(ByVal myConnection As Devart.Data.MySql.MySqlConnection, _ ByVal mySelectQuery As String, ByVal myParamArray() As Devart.Data.MySql.MySqlParameter) Dim myCommand As New Devart.Data.MySql.MySqlCommand(mySelectQuery, myConnection) Dim myMessage As String = "" Dim i As Integer For i = 0 To (myParamArray.Length - 1) myCommand.Parameters.Add(myParamArray(i)) myMessage = String.Concat(myMessage, " ", myCommand.Parameters(i).ToString()) Next Console.WriteLine(myMessage) Try myConnection.Open() myCommand.ExecuteNonQuery() Finally myConnection.Close() End Try End Sub Sub Main() Dim myP1 As New Devart.Data.MySql.MySqlParameter myP1.ParameterName = "DeptNo" myP1.Value = 10 Dim myP2 As New Devart.Data.MySql.MySqlParameter myP2.ParameterName = "DName" myP2.Value = "ACCOUNTING" Dim myParams(1) As Devart.Data.MySql.MySqlParameter myParams(0) = myP1 myParams(1) = myP2 Dim myConnection1 As New Devart.Data.MySql.MySqlConnection( _ "User Id=root;Host=localhost;Database=Test;") CreateCommand(myConnection1, "UPDATE Test.Dept SET DName = :DName WHERE DeptNo = :DeptNo", myParams) End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2