代码如下
        private void UserCheck() 
        {
            string sql = string.Format("select count(*) from Admin where LoginId={0} and LoginPwd={1}", TxtName.Text.Trim(), TxtPwd.Text.Trim());
            bool result = DBHelpe.Execulse(sql);
            if (result)
            {
                admin dm = new admin();
                dm.Show();
            }
namespace WindowsApplication1
{
class DBHelpe
    {
        public static string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
        public static SqlConnection coon = new SqlConnection(connction);
        public static bool Execulse(string sql)
        {
            coon.Open();
            SqlCommand cmd = new SqlCommand(sql,coon);
            int result = (int)cmd.ExecuteScalar();
            if (result > 0)
            {
                return true;
            }
            else
            {
                return false;
            }        }
    }
}
连接了数据库,为什么运行输入账号密码,点击登陆 也不提示出错,什么反应也没,卡住了!  到底怎么回事求解!!!! 

解决方案 »

  1.   

            private void button2_Click(object sender, EventArgs e)
            {
                if (Input())
                {
                    UserCheck();
                }
    登陆语句        
      

  2.   

    select count(*) from Admin where LoginId={0} and LoginPwd={1}
    int result = (int)cmd.ExecuteScalar();
    ---------------
    这个结果无论神马时候都返回1啊
    应该改成select * from Admin where LoginId={0} and LoginPwd={1}
      

  3.   

           public bool UserCheck() 
            {
                string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
                SqlConnection coon = new SqlConnection(connction);
                try
                {
                    coon.Open();
                    string sql = string.Format("select count(*) from Admin where LoginId='{0}' and LoginPwd='{1}'", TxtName.Text.Trim(), TxtPwd.Text.Trim());
                    SqlCommand cmd = new SqlCommand(sql, coon);
                    int result = (int)cmd.ExecuteScalar();
                    if (result > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    coon.Close();
                }
    }
    提示出错,并非所有的代码路径都有返回值!  哪出错了?
      

  4.   

    修改如下 public bool UserCheck()
            {
                bool flag = false;
                string connction = "Data Source=.;Initial Catalog=MySchool;User ID=sa;pwd=123456";
                SqlConnection coon = new SqlConnection(connction);
                try
                {
                    coon.Open();
                    string sql = string.Format("select count(*) from Admin where LoginId='{0}' and LoginPwd='{1}'", TxtName.Text.Trim(), TxtPwd.Text.Trim());
                    SqlCommand cmd = new SqlCommand(sql, coon);
                    int result = (int)cmd.ExecuteScalar();
                    if (result > 0)
                    {
                        flag= true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    coon.Close();
                }
                return flag;
            }
      

  5.   

    你开了无数次con.open,又不关,不卡才怪啊