Solved

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

Posted on 2011-02-17
4
305 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
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 29

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 29

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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