Solved

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

Posted on 2011-02-17
4
298 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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 400 total points
Comment Utility
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 29

Expert Comment

by:anarki_jimbel
Comment Utility
It seems you do everything OK, just confused with a collection:

                   
                   
var title = booklist[i].BootTitle;

Open in new window

0
 
LVL 29

Expert Comment

by:anarki_jimbel
Comment Utility
Ooops... Same as BurnieP... :) Didn't see
0
 

Author Closing Comment

by:stracqan
Comment Utility
Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now