i am working on asp.net mvc3. i am using database designed in sql server. i have added my database in App_Data using Ado.connection.
This is my table:

I want to access Code where ID=2
I am using this query:
ViewBag.pc = db.Product.Where(r => r.ID == p);
but this returns whole row. So what should i do to select particular column(here code). Please help me.
var code = db.Product.Where(r => r.ID == 2).Single().Codeshould work.If there could be more than one row (or none), you can use
FirstOrDefault()If there can only be one(or none), you can replace
FirstOrDefault()withSingleOrDefault()above.