Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Beginner - How to populate asp literal from Access database

Posted on 2009-05-05
4
Medium Priority
?
496 Views
Last Modified: 2012-05-06
Hey there,

I'm trying to populate an asp literal control on my asp.net page with data from an Access database.

I've got this to connect to my database:

<asp:AccessDataSource id="AccessDataSource2" runat="server" DataFile="app_data/pedigrees.mdb" SelectCommand="SELECT [Horse] FROM [Pedigrees] WHERE ([ID] = ?)">
                  <SelectParameters>
                        <asp:parameter DefaultValue="1" Name="ID" Type="Int32" />
                  </SelectParameters>
</asp:AccessDataSource>

I'd like to use an asp literal to get the value of "Horse" and display it on my page.

Any help will be greatly appreciated.

PS - I don't have a clue what I'm doing.
0
Comment
Question by:ttist25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:M3mph15
ID: 24311021
Hi,

Is there any reason behind using a <asp:Literal>. If not why not use a TextBOx or a Label.
0
 
LVL 10

Accepted Solution

by:
Christian de Bellefeuille earned 1200 total points
ID: 24311080
I don't know with an Access File, and from ASPX file, but if i would do it in code behind, i would do this like this:


    Private Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected
        Dim oCon As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
        oCon.Open()
        Dim oCmd As New SqlClient.SqlCommand("SELECT [Horse] FROM [Pedigrees] WHERE ([ID] = xxx)", oCon)
        Dim oRdr As SqlClient.SqlDataReader
 
        oRdr = oCmd.ExecuteReader()
        If oRdr.Read() Then
            Literal1.Text = oRdr("Horse").ToString()
        End If
    End Sub

Open in new window

0
 
LVL 1

Author Comment

by:ttist25
ID: 24311155
I ended up doing this which works:

<asp:Repeater ID="Repeater1" runat="server"
        DataSourceID="AccessDataSource2">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Horse") %>' />
            </ItemTemplate>
        </asp:Repeater>

It seems like if the asp:Label had a "DataSourceID" property it would make things really simple.  Am I missing something or is it really that complicated?
0
 
LVL 6

Assisted Solution

by:M3mph15
M3mph15 earned 800 total points
ID: 24311400
Yeh if you want to do it automatically in the aspx page you must put the control inside another control that has a DataSourceID property. Like a FormView, or in your case a Repeater. Or you might be able to even use a <div> tag....i think it has a property something like datasrc.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

722 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