View Full Version : Listing members from database

10-08-2010, 01:32 AM

I am currently building a website and I plan to show list of members that are registered on the website, I need some insight on how I would that with snippets of sample code if possible.

My idea is to have a loop that goes through the data base, in the loop the Labels would be created with the member names. Would this be a good method?


10-08-2010, 05:16 PM
Hey jt9000,

There are so many ways of doing this that I don't even know where to begin, and of course it all depends on the situation. Here's one I like which will probably suit your situation:

Let's say that on the .aspx page, you have a data control, such as a Repeater, named "Repeater_Results". Well in your code-behind, you would
have something like this, which would bind your data to the Repeater.

By the way, here is a link about data controls, which I'm guessing you're not familiar with either: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/default.aspx

And here's an even better link, whose example binds data to a Repeater in a very similar fashion as my snippet below, except it takes data from an XML file, and first saves it in a DataSet : http://www.w3schools.com/aspnet/aspnet_repeater.asp

using (SqlConnection mySqlConnection = new SqlConnection("[my connection string]"))
using (SqlCommand mySqlCommand = new SqlCommand("[my stored procedure call]", mySqlConnection))
using (SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
mySqlCommand.CommandType = CommandType.StoredProcedure;
Repeater_Results.DataSource = mySqlDataReader;


10-08-2010, 05:18 PM
...forgot to mention, the SQLCommand, SQlConnection, etc are all part of namespace System.Data.SqlClient