Solved

How do I access the data in my database variable in .NET & C#?

Posted on 2011-02-17
4
306 Views
Last Modified: 2012-05-11
Hello,

I'm new to .NET and I have been following the tutorials on the ASP.NET site for MVC 3 Apps using C#.

Everything is going smoothly but now I need to customize things and I'm stuck.

I have a variable set up that pulls data from my databases, which is then stored as an object.

I simply want to loop through that data set and pull out the column values individually.

Check out my code for a better explanation.

Thanks!!!!!!!!!
//in my controller

//this is an object that has two child objects
//that correspond to 2 tables in my database
//those child objects have all the column names
BookStoreEntities db = new BookStoreEntities();

 public ActionResult GetList()
        {
            //get all data from the BookList Table
            var booklist = db.BookList.ToList();

            //loop through each book and get the data
            //this is where im lost... Not sure how to get
            //to the Book Title etc...
            for (int i = 0; i < booklist.Count; i++)             {
                     //in here is where i want to access
                     //each columsn data and do something 
                     //with it...
                     //i tried:
                     var title = booklist.BootTitle(i);
                     //to no avail..
                 }
             }

Open in new window

0
Comment
Question by:stracqan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 400 total points
ID: 34921740
Hi,

You should be able to do it like this : (I changed your i variable for j because Experts Exchange is not allowing to post i between brackets.)

for (int j = 0; j < booklist.Count; j++)  {
    var title = booklist[j].BootTitle;
}

0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 34921907
It seems you do everything OK, just confused with a collection:

                   
                   
var title = booklist[i].BootTitle;

Open in new window

0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 34921916
Ooops... Same as BurnieP... :) Didn't see
0
 

Author Closing Comment

by:stracqan
ID: 34922647
Thanks!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question