Solved

Data Binding

Posted on 2011-03-10
4
206 Views
Last Modified: 2012-05-11
I am still learning C# and would like to know what the most efficient means is to bind data from a database into this simple application I have written. I'm still very confused by DataGrids, Data tables, Data Sets, Adapters, etc. I think there's something basic I am not getting.

The application is as follows:

The user enters some parameters X, Y, Z about themselves, and then the application goes to the datbase and finds X, Y, Z (all keys in the table) and returns A, B.  There is only ONE resulting row containing A and B, never more than one row. I need to display A and B on the page in a Label field, so how do I get this result and display it?

What should I use? Seems like overkill to use a Data grid or data table for just one resulting record.

Once I get the result set back, can I bind it to a label field? or does it have to be bound to a repeater (also overkill for this application).

I got as far as the DataAdapter, but I'm not sure what to do from there. Help!
0
Comment
Question by:vcbertini
  • 2
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
Comment Utility
You basically have a few groups of object that go together. A DataSet is a container object that holds one or more DataTables. A DataAdapter acts as an intermediary between between the DataSet and your database. DataReaders are fast, light-weight data objects that give you forward-only access to your data (this would be the most suitable in your scenario).

The DataGrid, Repeater, etc, are UI elements that display data stored in DataTables/DataSet or pulled back with a DataReader.

Labels are dumb, in the sense that the do not directly support databinding in their own right. They can pull data from a data source, but only when they are inside a data-aware control such as a grid or repeater, etc.  
0
 

Author Comment

by:vcbertini
Comment Utility
So I would probably have to use a repeater even though there's nothing that will repeat?

...and I would bind the repeater to the data reader?
0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Not necessarily. A DetailsView might suit your purpose because it is designed for displaying a single record at a time:

    http://msdn.microsoft.com/en-us/library/s3w1w7t4.aspx
0
 

Author Closing Comment

by:vcbertini
Comment Utility
Hmm... Food for thought. Thank you very much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

14 Experts available now in Live!

Get 1:1 Help Now