C#高职计算机导论考试系统设计与实现(17)_毕业论文

毕业论文移动版

毕业论文 > 计算机论文 >

C#高职计算机导论考试系统设计与实现(17)


            {
                // 查询字符串
                string sql = string.Format("select count(*) from Teacher where LoginId='{0}' and LoginPwd='{1}'",
                                    loginId, loginPwd);
                // 测试数据库连接
                try
                {
                    // 创建 Command 对象
                    SqlCommand command = new SqlCommand(sql, DBHelper.connection);

                    // 打开数据库连接
                    DBHelper.connection.Open();

                    // 验证是否为合法用户名
                    int count = (int)command.ExecuteScalar();
                    if (count < 1)
                    {
                        message = "用户名不存在或密码错误!";
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    message = "操作数据库出错!";
                    Console.WriteLine(ex.Message);
                    return false;
                } (责任编辑:qin)