Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:42:10+00:00 2026-06-05T16:42:10+00:00

I created a C# application and integrated an Access DB (with 3 populated tables).

  • 0

I created a C# application and integrated an Access DB (with 3 populated tables).

Now I try to get data from the Access DB-tables to display it in a TextBox, but nothing is visible.

Thank you in advance.

UPDATE: namespace –> using System.Data.OleDb;

Here is the code:

    OleDbDataReader myReader;
    OleDbConnection myCon;
    OleDbCommand myQuery;

    public Form1()
    {
        InitializeComponent();
        myCon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\UserName\\Desktop\\MyClubAdministration\\MyClubAdministrationDB.accdb;Persist Security Info=False;");
        myCon.Open();
        myQuery = new OleDbCommand("select * from Lid, Lidgeld, Lidmaatschap", myCon);
        myReader = myQuery.ExecuteReader();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        textBox1.Text = myReader.GetInt32(0).ToString();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:42:11+00:00Added an answer on June 5, 2026 at 4:42 pm

    You need to Read before GetInt32 on an OleDBDataReader

    private void Form1_Load(object sender, EventArgs e)     
    {         
        myReader.Read();
        textBox1.Text = myReader.GetInt32(0).ToString();     
    } 
    

    However this code is very error prone.
    Try to isolate the database operarations in a private methods and call just from one point without splitting between constructor and form_load.

    private void ReadFromDB()
    {
        using(OleDbConnection myCon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\UserName\\Desktop\\MyClubAdministration\\MyClubAdministrationDB.accdb;Persist Security Info=False;"))
        {
             myCon.Open();             
             OleDbCommand myQuery = new OleDbCommand("select * from Lid, Lidgeld, Lidmaatschap", myCon);
             OleDbDataReader myReader = myQuery.ExecuteReader();
             if(myReader.HasRows)
             {
                  myReader.Read();
                  textBox1.Text = myReader.GetInt32(0).ToString();
             }
        }
    }
    

    call that method after InitializeComponent();

    As a side note, I will avoid the globals for the database operations. With connection pooling the performance cost to open and reopen a connection is really minimal, while the complexity of housecleaning grows exponentially.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created application where i just need to access data form assets folder.
I created an application and all the db tables have 'created,modified' fields that filled
I created an application in Access 2003 and continued to work on it on
I have integrated evernote in my application by downloading sample code from its site.
I have created an iPhone application. I have integrated with SoundCloudAPI. To authorize it,
I have created an iPhone test application. Also I have integrated SoundCloud with the
I created a new MVC application and added an Entity Framework model generated from
I'm developing an asp.net application which has Windows Authentication enabled(anonymous access disabled). I've created
I created a C# console application, and need to access my database. var connectionString
I need to create a flash projector application which can be interacted with, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.