Thursday, 15 July 2010

c# - Passing parameter to Stored Procedure using DbContext -


I have a stored procedure that accepts a string parameter, below is my code

 < Code> var DatabaseContext = (DbContext) this.ManagementContext; DatabaseContext.Database.Connection.Open (); (Var command = database consort. Databases. Connection. CreateCommand ()) using {command.CommandText = "StoredProcName"; Type the command. Type command = command type Stored procedure; DbParameter param = command.CreateParameter (); Param.DbType = DbType.String; Param.Direction = Parameter Direction.Input; Param.Value = "Development"; Command.Parameters.Add (Ultimate);  

text "itemprop =" text ">

If the name of your stored procedure is" StoredProcName ", and the parameter named" paragraph 1 " .

  var Expected Results = ((IObjectContextAdapter) This. DatabaseContext.ExecuteStoreCommand ("stored ProcName @ paragraph 1," "development");  

Then, you will get stored procedure results in "executed result".


No comments:

Post a Comment