private void FormZT_Load(object sender, EventArgs e)
        {
            comboBoxzt.Focus();
            DataGn gn = new DataGn();
            string s="";
            s = gn.zcb() + "fterp";
            try
            {
                SqlConnection myConn = new SqlConnection(s);
                myConn.Open();
                SqlCommand myCmd = new SqlCommand("select * from tb_zt", myConn);
                SqlDataReader myRead = myCmd.ExecuteReader();
                if (myRead.HasRows)
                {
                    while (myRead.Read())
                    {
                        comboBoxzt.Items.Add(myRead[0].ToString() + "(" + myRead[1].ToString() + ")");
                    }
                }
                myRead.Close();
                myConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);//运行后总是循环出现错误提示
            }     
        }

解决方案 »

  1.   

    嗯。我也愁坏了没有办法只能CTRL+ALT+DEL。正常只会出现一次错误提示的。我也纳闷了
      

  2.   

    检查 FormZT 被谁调用了~
      

  3.   

    出错提示是什么?
    如果是循环出错的话,那就说明:
     while (myRead.Read())
                        {
                            comboBoxzt.Items.Add(myRead[0].ToString() + "(" + myRead[1].ToString() + ")");
                        }
    这里有问题
      

  4.   

    try catch 应该是循环了
      

  5.   

    其实还有一种方法,你先把try catch注释掉,调试时出错就会停在错误的地方,那就方便地知道出错在哪了.
      

  6.   

    不要Show东西在FormLoad,否则有可能会重复引起FormLoad