using (var _dbContext = new TestDbContext()) { //Open Database connection _dbContext.Database.Connection.Open(); //Create command object DbCommand _cmd = _dbContext.Database.Connection.CreateCommand(); //Set procedure name as command text _cmd.CommandText = "SPName"; //Set command type to stored procedure _cmd.CommandType = CommandType.StoredProcedure; // Set input parameter value _cmd.Parameters.Add(new SqlParameter("@Id", 100)); //Set Out put parameter value var _resultParam = new SqlParameter("@Result", SqlDbType.NVarChar, 1000) { Direction = ParameterDirection.Output }; _cmd.Parameters.Add(_resultParam); _cmd.ExecuteReader(); return _strResult = _resultParam.Value != null ? _resultParam.Value.ToString() : "Error Message!!!"; }
Programming is Easy…
Advertisements