我用的是VS2005,下面的代码提示错误!
问题1:
            ConnDB us = new ConnDB();
            SqlCommand cmd=new SqlCommand();
            cmd.Connection = us.Cn;
            cmd.CommandText="select * from Users where UserCode='" + textBox1.Text  +"'";
            cmd.CommandType = CommandType.Text;
            SqlDataReader logi = cmd.ExecuteReader();
          运行到最后一行时提示:Invalidoperationexception was unhandled
ExecuteReader:Connection propertyh has not been initialized.
但是之前运行都没错的啊问题2:在窗体中按回车键时,默认到某个按钮上,或是按ESC键时默认到某个键,在哪里设置呢!
谢谢!

解决方案 »

  1.   

    1)有必要看看你ConnDB里的代码2)设置窗体的keyPreview属性为true
    然后   private void Form2_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Escape)
                {
                    this.button1.Focus();
                }
                else if(e.KeyCode == Keys.Enter)
                {
                    this.button2.Focus();
                }        }