assigning data extracted from a database to a label in ASP.NET

L

Libra Blue

I am extracting data from a database in a very normal SELECT query.
The point is that I want to put some of the data (in the row(s)
extracted in labels not a datagrid or a table. Any idea how??

here's my code (so far!!!)

protected System.Web.UI.WebControls.Label Label1;

DataSet DS = new DataSet ();
OleDbConnection MyConnection;
OleDbDataAdapter MyCommand;

private void Page_Load(object sender, System.EventArgs e)
{
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4;" +
"Data Source=C:\\Documents and Settings\\librablue\\My " +
"Documents\\Visual Studio Projects\\Books\\Books.mdb";
MyConnection = new OleDbConnection ( ConnectionString );
MyCommand = new OleDbCommand ( "SELECT * FROM [Books] WHERE
[Books].[Serial]=\'"
+ Session["Serial"] + "\'", MyConnection );
}

and by the way, the OleDbDataReader thing didn't work, or at least I
wasn't able to use it correctly...

Libra Blue
 
N

Nicholas Paldino [.NET/C# MVP]

Libra,

Once you have the connection, you can call ExecuteReader, which will
allow you to pass through the result set, forward only. From there, you can
assign the Text property of the label (I assume there is one) to the value
you want from the database.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top