Let's now discuss how we can use the entity client to insert the Department
data. To do this, follow these simple steps:
Create an instance of the
EntityConnection
class as follows:EntityConnection conn = new EntityConnection ("Name=PayrollContainer");
Open the connection by using the
EntityConnection
instance:conn.Open();
Create an
EntityCommand
instance and specify theCommandText
andCommandType
properties:EntityCommand cmd = conn.CreateCommand(); cmd.CommandText = "PayrollEntities.Insert_Department"; cmd.CommandType = CommandType.StoredProcedure;
Add parameters using the
AddWithValue
method of theParameters
collection of theEntityCommand
instance:cmd.Parameters.AddWithValue ("DepartmentName", "Finance");
Next, execute the procedure by using the
ExecuteNonQuery
method:cmd.ExecuteNonQuery();
Here is the complete code listing:
using (EntityConnection conn = new EntityConnection("Name= PayrollContainer ")) { try ...