Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 8th, 2004, 11:05 PM
Registered User
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default databind database to label

I want to display a record from an access database to a label. I've tried lots of code with no success.:(

Please help

Thank You


Old October 8th, 2004, 11:52 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts

What have you tried and what are the errors you are getting?

Old October 9th, 2004, 07:57 AM
Registered User
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Here's my label:

<asp:label id=Label1 style="Z-INDEX: 102; LEFT: 408px; POSITION: absolute; TOP: 264px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ordernumber", "{0:c}") %>' Width="72px">
Here's my code behind:

 Dim ds As New DataSet
        ds = New DataSet("cbphotoalbumdb")

        Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\inetpub\wwwroot\cbphotoalbum2\_database\dotnet. mdb"

        Dim connection1 As OleDbConnection = New _

        Dim command1 As OleDbCommand = _
        New OleDbCommand("SELECT orders.ordernumber, shopper.lastname, shopper.firstname, orders.orderdate, orders.ordercomplete FROM shopper, orders WHERE ordernumber=200")
        command1.CommandType = CommandType.Text

        command1.Connection = connection1

        Dim oledbdataadapter1 As OleDbDataAdapter = New OleDbDataAdapter

        oledbdataadapter1.SelectCommand = command1


Here's my error message:

Compiler Error Message: BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.
Thank You:)

Old October 17th, 2004, 04:18 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

For just getting a text value from your database to a label, just assign it in the code-behind:

'Select data from database
label.Text = <value from database object>

Similar Threads
Thread Thread Starter Forum Replies Last Post
Databind DarkForce ASP.NET 2.0 Basics 5 January 25th, 2011 12:04 PM
About the Databind() kuuy BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 1 November 15th, 2006 12:56 PM
Databind in TextBox kapi.goel C# 1 April 26th, 2006 05:51 AM
Can't get RadioButtonlist with databind nayalksrs123 .NET Web Services 0 January 15th, 2005 06:29 AM
DataBind Problem liorlankri ADO.NET 3 November 2nd, 2004 04:13 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.