Mark Tabor

Mark Tabor

  • 569
  • 1.9k
  • 430.2k

show details of the selected record

Sep 25 2016 3:13 AM
I have a simple website in mvc , i am new to mvc i have services in that first view and i have a read more button with each service to show the service details  when i click the read more button i want to show the details of that service below is my service class 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
namespace BusinessApplicationTemplate.Models
{
public class Service
{
public List<Service> Getdatabyid(int id)
{
String connectionString = "Data Source=ASPKCO-DANISH\\SQLEXPRESS1234;Initial Catalog=PakeezaSodagran;Integrated Security=True;";
String sql = "SELECT * FROM Service where ID = "+ id;
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
var model = new List<Service>();
while (rdr.Read())
{
var service = new Service();
service.ID = Convert.ToInt32(rdr["ID"]);
service.Name = rdr["Name"].ToString();
service.Description = rdr["Description"].ToString();
service.Image = rdr["Image"].ToString();
model.Add(service);
}
return model;
}
}
}
}
 
Can any one give me the example it would be much easier for me to follow  
 

Answers (2)