Thamsanqa Ngcongwane

Thamsanqa Ngcongwane

  • NA
  • 184
  • 24.9k

Want to Display Data from a Stored Procedure

Oct 17 2019 1:58 AM
How to display specific record from a Stored Procedure.
 
My View:
<div class="col-lg-6">
<div class="form-group">
<div class="input-group">
<span asp-validation-for="Item2.Name" class="text-danger input-group-addon"></span>
<input asp-for="Item2.Name" type="text" class="form-control" placeholder="First Name" name="Name">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span asp-validation-for="Item2.Surname" class="text-danger input-group-addon"></span>
<input asp-for="Item2.Surname" type="text" class="form-control" placeholder="Surname" name="Surname">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span asp-validation-for="Item2.Gender" class="text-danger input-group-addon"></span>
<input asp-for="Item2.Gender" type="text" class="form-control" placeholder="Gender" name="Gender">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span asp-validation-for="Item2.IDorPassportNo" class="text-danger input-group-addon"></span>
<input asp-for="Item2.IDorPassportNo" type="text" class="form-control" placeholder="ID Number Or Passport Number" name="IDorPassportNo">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span asp-validation-for="Item2.HighestQualificationID" class="text-danger input-group-addon"></span>
<input asp-for="Item2.HighestQualificationID" type="text" class="form-control" placeholder="Highest Qualification" name="HighestQualificationID">
</div>
</div>
</div>
 
My Model:
 
public int ID { get; set; }
public int VacancyID { get; set; }
public int UserID { get; set; }
[NotMapped]
public string Name { get; set; }
[NotMapped]
public string Surname { get; set; }
[NotMapped]
public string Gender { get; set; }
 
My C# Code: 
 
var loginId = HttpContext.Session.GetInt32("loginId");
User user = new User();
Documents documents = new Documents();
using (var cmd = new SqlCommand("sp_Users", conn))//Users
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader userReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
SqlParameter usertId = cmd.Parameters.AddWithValue("@UserID", loginId);
while (userReader.Read())
{
}
userReader.Close();
conn.Close();
}
//This returns a View For Application of a Candidate
return View();
 

Answers (3)