Solved

Data Binding

Posted on 2011-03-10
4
207 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
ID: 35100063
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
ID: 35100083
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
ID: 35100101
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
ID: 35100122
Hmm... Food for thought. Thank you very much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Runtime Error 2 28
What .NET URL re-routing tool did I use? 2 37
Turn on intranet settings 1 41
Adding  DYMO Labelprinter to c# client application 4 8
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

26 Experts available now in Live!

Get 1:1 Help Now