public ActionResult PositionCate() { PositionCate objBlog = new PositionCate(); DataAccessLayer objDB = new DataAccessLayer(); //calling class DBdata objBlog.ShowallPositionCate = objDB.SelectPositionCate(); return(View(objBlog)); }
public List <PositionCate> SelectPositionCate() { SqlConnection con = null; DataSet ds = null; List <PositionCate> custlist = null; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString()); SqlCommand cmd = new SqlCommand("ShowPositionCate", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; ds = new DataSet(); da.Fill(ds); custlist = new List <PositionCate>(); var table = ds.Tables[0]; for (int i = 0; i < table.Rows.Count; i++) { PositionCate cobj = new PositionCate(); cobj.ID = Convert.ToInt32(table.Rows[i]["ID"].ToString()); cobj.Name = table.Rows[i]["Name"].ToString(); custlist.Add(cobj); } return(custlist); } catch { return(custlist); } finally { con.Close(); } }