using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Threading;namespace thread实验
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            Thread th = new Thread(new ThreadStart (f.eg));
            th.Start();        }
        private void eg()
        {
            SqlConnection conn = new SqlConnection("Data Source=172.24.95.180;Initial Catalog=pubs;User Id=sa;Password=sa");
            SqlDataAdapter adpt = new SqlDataAdapter("",conn );
            DataSet dstem = new DataSet();
            try
            {
                conn.Open();
                adpt.Fill(dstem ,"f");
                conn.Close();                for (int i = 0; i < dstem.Tables["f"].Rows.Count; i++)
                {
                    this.checkedListBox1.Items.Add(dstem .Tables["f"].Rows [i][0].ToString ());
                }
            }
            catch { 
            
            }
        }
    }
}

解决方案 »

  1.   

    如果调试应该会有错误的,可给你try catch住了,你直接运行不调试看看啥情况的
      

  2.   

    老大, 调试过了,没有报错误,  但是就是显示不出来  , 
    你能 给我个明路. 
    哦我用的是c#2008 express版本的
      

  3.   

    你在线程里操作控件,要异步调用。checkedListBox1.Invoke(代码方法)
      

  4.   

    你用try{}catch(Exception ex){messagebox.show(ex.message);}捕获异常看看,应该是楼上说的线程操作线程以外的控件造成的,
      

  5.   

    不能直接this.checkedListBox1.Items.Add(dstem .Tables["f"].Rows [i][0].ToString (
    需要用委托才可以.
    checkedlistbox1是主线程创建的.
    不能用其他线程直接访问.
      

  6.   

    不能在线程中操作界面UI
    和还有 你线程为什么
     Form1 f = new Form1(); 
     Thread th = new Thread(new ThreadStart (f.eg)); 
    不是this?