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 8616187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:33:29+00:00 2026-06-12T05:33:29+00:00

im working in WinForms C#. for some reason when I want to populate my

  • 0

im working in WinForms C#.

for some reason when I want to populate my listBox it stops and says my database is corrupt.
I have added a repair line and the codes run afterwards, but nothing happends. My listbox is not populated.

Here is the code im using.:

public void button1_Click(object sender, EventArgs e)
    {
        SqlCeConnection cn = new SqlCeConnection(@"Data Source = Database1.mdf");
        cn.Open();
        SqlCeCommand cm = new SqlCeCommand("SELECT * FROM tblprojects ORDER BY Projekt_liste ASC", cn);

        try
        {
            SqlCeDataReader dr = cm.ExecuteReader();

            while (dr.Read())
            {
                ListBox project_list = Application.OpenForms["Form1"].Controls["tabControl1"].Controls["tabPage1"].Controls["Project_list"] as ListBox;
                project_list.Items.Add(dr["Projekt_liste"].ToString());
            }
            cn.Close();
            cn.Dispose();
        }
        catch (Exception ex)
        {
        }
    }

    public void button2_Click(object sender, EventArgs e)
    {

        SqlCeConnection cn = new SqlCeConnection();

        SqlCeEngine engine = new SqlCeEngine("Data Source = Database1.mdf");

        if (false == engine.Verify())
        {
            MessageBox.Show("Database is corrupted.");
            engine.Repair(null, RepairOption.RecoverAllPossibleRows);
        }
    }
  • 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-12T05:33:30+00:00Added an answer on June 12, 2026 at 5:33 am

    For example if you want to load the items

    1. make sure you have a ListBox on the winform
    2. name the ListBox 
    3. Create a ListItem 
    4 Add the ListItem to the ListBox
    
    while(dr.Read())
    {
      ListViewItem obj=new ListViewItem(Convert.ToString(dr[0]),Convert.ToString(dr[1]);
      //in object of ListViewItem give display member at first and give value member at second position 
      listView1.Items.Add(obj); // add object to the listbox
    }
    

    Here are a few links that you can use as well to show different ways on how to populate a ListBox

    one is Windows and the other will be if you are using or plan to use ASP.NET

    Populate a ListBox when using SQLDataReader

    asp.net SqlDataReader example: how to use Read() method to populate ListBox

    Populate ASP.NET ListBox using SqlDataReader

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

Sidebar

Related Questions

(I'm working in winforms using c#) I have a Listbox ,with some items added
I am working on a winforms app and I have added some controls dynamically
I am working on C# 3.5 winforms project. I want to execute some code
I have some nice, working edit-undo functionality in my winforms application. It works using
I have been working on using mvp to wire up some winforms in C#.
I'm working in winforms, and I'm attempting to link in some events any time
I am working on a C# WinForms application that uses some DevExpress controls. I
I'm working with a WinForms app. I have an RDLC report that will be
I am working on a winforms application using C#. I have a dictionary with
My team working in a project using Winforms application(c#) & MSSQL 2005 as database.

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.