Previous Topic

Next Topic

Calling Stored Procedures from .NET

From .NET applications, use the CtreeSqlCommand() object to execute stored procedures. The following example illustrates use of a stored procedure with parameters.

Invoking a Stored Procedure from a .Net Application


// Create a new connection object.
String conString = "User=ADMIN;Password=ADMIN;Database=ctreeSQL";
CtreeSqlConnection hConnection = new CtreeSqlConnection(conString);

// Open the connection.
hConnection.Open();

// Create a new command object.
CtreeSqlCommand hCommand = new CtreeSqlCommand(hConnection);
hCommand.CommandText = "order_parts";

// Set the command type.
hCommand.CommandType = CommandType.StoredProcedure;

// Construct a parameter and add to the command.
CtreeSqlParameter param1 = hCommand.Parameters.Add("part_num", CtreeSqlDbType.Integer);

// Set the value for part number.
param1.Value = 318;

// Execute the command and create a DataReader object.
CtreeSqlDataReader hReader = hCommand.ExecuteReader();