Results 1 to 3 of 3
  1. #1
    cemsultan is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    2

    Question Access Database - assigning values to form objects(labels)

    I searched through a lot but couldn't figure out how to do this. I am sure it is because of my being amateur in this field.
    I am trying to build a web program for my students so that they can practice the foreign language more on their own. So, what I come up with is a showing a text in the target language and then asking student to read it. After a few tryings, I found out that every time creating a new practice page is taking too long, so I thought maybe I could just put the words or sentences into the database under unit1 or unit2 column, and the webpage will pull these datas and show them to students as practice questions.


    This is how practice page looks like: practice page
    as you see on the picture, in place of each [label] area, there would be a word/text.
    This is how database look like: questions database
    with all the research and everything, I could get until here

    Code:
    
    
    Code:
    using System;
    using System.Data.OleDb;
    
    namespace language
    {
    public partial class exercise1 : System.Web.UI.Page
    {
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            string connectionString =@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\inetpub\wwwroot\www\language\data2.accdb";
    
            string queryString ="SELECT unit1 FROM questions";
            try
            {
                using(OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    OleDbCommand command = new OleDbCommand(queryString, connection);
                    connection.Open();
                    OleDbDataReader reader = command.ExecuteReader();
    
                    while(reader.Read())
                    {
    
                        Label1.Text = reader.GetString(22).ToString();
                        Label3.Text = reader.GetString(23).ToString();
                        Label5.Text = reader.GetString(24).ToString();
                        Label7.Text = reader.GetString(25).ToString();
                        Label9.Text = reader.GetString(26).ToString();
    
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('error error error')</script>");
    
            }
        }
    }



    This is how the code looks like now, I copied it from another question here, but again didn't work. I tried DataTable, couldn't make it work either. You help will be appreciated a lot. I am sorry for any irregularities with everything here.
    Thank you for your help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    this is java and wont quite work in access, but

    set a label:
    label1.caption = "caption 1"
    label2.caption = obj.value

  3. #3
    cemsultan is offline Novice
    Windows 10 Access 2007
    Join Date
    Mar 2017
    Posts
    2
    I am actually doing it here :

    Label1.Text = reader[0].ToString();

    but, somehow I couldn't manage to connect the specific database row to the form.

    this was me before starting this project =
    and now =

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing values vs. objects
    By Monterey_Manzer in forum Programming
    Replies: 1
    Last Post: 09-26-2014, 12:31 PM
  2. Replies: 2
    Last Post: 12-11-2012, 12:04 PM
  3. Assigning values to Text Boxes
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 12-11-2010, 01:26 AM
  4. Assigning values to duplicate records
    By matteu1 in forum Queries
    Replies: 3
    Last Post: 02-17-2010, 10:35 PM
  5. Assigning Values/Scorecard
    By nicholali in forum Access
    Replies: 0
    Last Post: 11-17-2008, 03:20 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums