PreviousNext
Help > Easycom .NET > System.Data.EasycomClient namespace > EacParameter > Example
Example

 

Different parameters are used into the INSERT SQL request:

First syntax:

EacCommand cmd = ConnectionIBM.CreateCommand();

 

cmd.CommandText = "INSERT INTO SP_CUST (FIRSTNAME, LASTNAME, CITY)        VALUES(:param0, :param1, :param2)";

 

cmd.Prepare();

 

EacParameter param0 = new EacParameter("param0", "rob");

cmd.Parameters["param0"] = param0;

 

EacParameter param1 = new EacParameter("param1", "ced");

cmd.Parameters["param1"] = param1;

 

EacParameter param2 = new EacParameter("param2", "sophia");

cmd.Parameters["param2"] = param2;

 

cmd.ExecuteNonQuery();

 

Second syntax: the Prepare is put after having added the parameters

EacCommand cmd = ConnectionIBM.CreateCommand();

 

cmd.CommandText = "INSERT INTO SP_CUST (FIRSTNAME, LASTNAME, CITY)        VALUES(:param0, :param1, :param2)";

 

EacParameter param0 = cmd.Parameters.Add("param0", DbType.AnsiString, 10);

param0.Direction = ParameterDirection.Input;

param0.Value = "ced";

 

EacParameter param1 = cmd.Parameters.Add("param1", DbType.AnsiString, 10);

param1.Direction = ParameterDirection.Input;
param1.Value =
"ced";

 

EacParameter param2 = cmd.Parameters.Add("param2", DbType.AnsiString, 15);

param2.Direction = ParameterDirection.Input;

param2.Value = "16";

 

cmd.Prepare();

 

cmd.ExecuteNonQuery();