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

  • SEARCH
  • Home
  • 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 561539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:27:37+00:00 2026-05-13T12:27:37+00:00

C# (.NET 3.5) I have an SQLite database with two tables – employees (the

  • 0

C# (.NET 3.5)

I have an SQLite database with two tables – employees (the first column being id INTEGER PRIMARY KEY), and holidays (id INTEGER – meaning the ID of the employee; start DATE, end DATE – self-explanatory).

My form contains textboxes, checkboxes etc. to represent the employee details – but say I’d also like a list box, listing all the holidays for the currently selected employee.

So I need a data relation, as the list box is supposed to display only holidays one person at the time (IDs on both datatables needs to match).

        var command = new SQLiteCommand("SELECT * FROM employees; SELECT * FROM holidays");
        var connection=new SQLiteConnection(@"data source=C:\employees.db");
        command.Connection = connection;
        SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
        DataSet d = new DataSet();
        adapter.Fill(d);                        

        DataTable employees = d.Tables[0];

        // [...]
        // here I'm databinding my textboxes etc. to various columns 
        // of the employees data table - this works fine, navigation works well etc.
        // [...]

        DataTable holidays = d.Tables[1];            

        DataRelation relation;
        DataColumn master = employees.Columns[0];
        DataColumn slave = holidays.Columns[0];
        relation = new DataRelation("relation", master, slave);
        d.Relations.Add(relation);

        var dsView = holidays.DefaultView;
        listBox1.DisplayMember = "holidays.relation.start"; // <= it wouldn't look good like that of course, but I just want to get the thing to work for now
        listBox1.DataSource = dsView;
  • but all I get is a listbox filled up with a bunch of “System.Data.DataRow”
    In this implementation, I tried to follow the tutorial I found on Akadia… Where do I go wrong? Thanks
  • 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-05-13T12:27:37+00:00Added an answer on May 13, 2026 at 12:27 pm

    First of all, you have named variables employees and holidays, but that does mean the tables within the dataset have names changed; they are still set to the default names, which, in your case are table and table1. (They would normally be table, table1 … tableN)
    That means that your display member property should be as follows:

    listBox1.DisplayMember = "table.relation.start";
    

    Also, make sure you databind to the dataset itself rather than the holiday table within the dataset as follows:

    listBox1.DataSource = d;
    

    With these two changes, you should find that it works; this.BindingContext should help in navigating the parent records as you will notice only 1 set of child (holiday) results are shown at at time.

    Complete modified code as follows:

        var command = new SQLiteCommand("SELECT * FROM employees; SELECT * FROM holidays");
        var connection=new SQLiteConnection(@"data source=C:\employees.db");
        command.Connection = connection;
        SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
        DataSet d = new DataSet();
        adapter.Fill(d);                        
    
        DataTable employees = d.Tables[0];
    
        // [...]
        // here I'm databinding my textboxes etc. to various columns 
        // of the employees data table - this works fine, navigation works well etc.
        // [...]
    
        DataTable holidays = d.Tables[1];
    
        DataRelation relation;
        DataColumn master = employees.Columns["id"];
        DataColumn slave = holidays.Columns["employeeid"];
        relation = new DataRelation("relation", master, slave);
        d.Relations.Add(relation);
    
    
        listBox1.DisplayMember = "table.relation.start"; // <= it wouldn't look good like that of course, but I just want to get the thing to work for now
        listBox1.DataSource = d;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pre-made SQLite database that I am downloading from the net via
I have a datalogging application (c#/.net) that logs data to a SQLite database. This
I have a desktop .NET WPF application witch uses an embedded database (SQLite). Where
I have a nullable double column in my SQLite database. When reading from the
I have a .NET application that uses a sqlite database. In the latest release
We have .NET code (C#) that writes to a SQLite database, which is then
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have a database where I store two different kinds of data. One table
I have used sqlite database in some of my iphone applications but as you
I'm trying to connect to SQLite database with Ecplise but I have some errors.

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.