?
Solved

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

Posted on 2011-02-17
4
Medium Priority
?
310 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 1600 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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