locked
Fill Access data into running text RRS feed

  • Question

  • User1821983619 posted

    I want to supply latest update info from my Access data base into text describing the database, e.g. "the database was last updated on (date field from SQL Query) and now contains (number of records field from SQL query) records".

    I have tried an AccessDataSource which returns the desired fields when tested, but cant make <%# Eval("Fieldname") %> return anything into a Label Text. What am I doing wrong?

    Sunday, February 1, 2009 12:30 PM

Answers

All replies

  • User-821857111 posted

    Have alook at this: http://www.mikesdotnetting.com/Article.aspx?ArticleID=64.  If that doesn't help, please show your code.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 1, 2009 1:26 PM
  • User1821983619 posted
    Have read your linked document - see only 2 labels in the ASP.net code (you say there are 4) - confused.. The DataSet/dataReader intricacies are beyond me, I regret; as are the tricks to fetch a number of rows from the database. My query returns exactly 1 record, which contains only the values I need. My AccessDataSource looks like this: <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/PNR.mdb"

    SelectCommand="SELECT [Notiser], [Relationer], [Uppdaterad] FROM [qStatus]">

    </asp:AccessDataSource>

    The Access query is SELECT DCount("*","HUVUDTABELL") AS Notiser, DCount("*","RELATION") AS Relationer, Max(Huvudtabell.Uppdaterad) AS Uppdaterad
    FROM Huvudtabell
    GROUP BY DCount("*","HUVUDTABELL"), DCount("*","RELATION");

    I simply count the number of records in 2 tables and get the max value in the "Uppdaterad" field of table 'HUVUDTABELL' which is updated every time I edit a record

    No need for WHERE or ORDER clauses - it is all there to get, but I can't.

    Please elaborate!

    Sunday, February 1, 2009 2:34 PM
  • User-821857111 posted

    "4" labels is a typo.  I'll correct that shortly to "2".  Beyond that, I'm not sure what is confusing you, so I don't know what elaboration you need.

     

    Sunday, February 1, 2009 2:59 PM
  • User1821983619 posted

     

    So sorry, don't understand how your document applies to my problem.

    Sunday, February 1, 2009 4:51 PM
  • User-821857111 posted

    I thought your problem was in trying to take values from an AccessDataSource control and display them in a Label control:

    I have tried an AccessDataSource which returns the desired fields when tested, but cant make <%# Eval("Fieldname") %> return anything into a Label Text. What am I doing wrong?

     

    If I have got that wrong, and the link I posted which shows how to do that doesn't help, I suggested you post the code you have been trying to get working.  That suggestion still stands.  You have shown the AccessDataSource control, and added some detail about qStatus which doesn't seem pertinent to the problem  But also show the Label control markup.  Is it standalone? In a FormView or something? 

     

    Sunday, February 1, 2009 5:36 PM
  • User1821983619 posted

    However many times I read your document I can only see that it's about SQLDataSource, not AccessDataSource - AccessDataSources don't need Connection strings and my query doesn't need a select parameter.

    But of course, if you say your code does what I need it certainly does - only I don't understand what I need to change to make it work with an AccessDataSource.

    There are also several details in your code that I don't understand, such as why I should iterate when there only is one row, but if it works I don't care if I understand. I am a history researcher publishing my results on the web, not a programmer.

    My labels are just inserted at the appropriate position in a text, as I explained in my first post: they are the simplest possible:

    text<asp:Label ID="Label1" runat="server" Text='<%# Eval ("Uppdaterad")' %>'></asp:Label>moretext

    Monday, February 2, 2009 4:03 AM
  • User1821983619 posted

    Got it to work after changing a few things in your code; thank you!

    The AccessDataSource declaration is now 

     <asp:AccessDataSource ID="AccessDataSource1" runat="server"
    DataFile="~/App_Data/PNR.mdb"
    DataSourceMode="DataReader"
    SelectCommand="SELECT [Notiser], [Relationer], [Uppdaterad] FROM [qStatus]">
    </asp:AccessDataSource>

    and the code behind
    ...
    using System.Data.OleDb;
    ...
    OleDbDataReader rdr = (OleDbDataReader)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
    while (rdr.Read())
    {
          Label1.Text = rdr[
    "Uppdaterad"].ToString().Substring(0,10);
          Label2.Text = rdr[
    "Notiser"].ToString();
          Label3.Text = rdr[
    "Relationer"].ToString();
       }
       rdr.Close();
    }

    Monday, February 2, 2009 5:29 AM
  • User-821857111 posted

    However many times I read your document I can only see that it's about SQLDataSource, not AccessDataSource
     

    From memory, I'm sure that I said in the article that an AccessDataSource control is almost identical, but I see you have found that minimal changes were needed. I understand that you are not a web developer, along with many people who post here, so it's probably helpful to you to point out to you that many times, people will link to an article that explains the principal behind what you want, and not one showing the actual code you need (uneless you a really lucky!).

    There are also several details in your code that I don't understand, such as why I should iterate when there only is one row
     

    Because you have to [:D].  Blame Microsoft.  That's how it works.

    You got there in the end, though.  Well done!

     

    Monday, February 2, 2009 9:01 AM