毕业论文

打赏
当前位置: 毕业论文 > 计算机论文 >

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

时间:2016-11-22 23:24来源:毕业论文
{ // 查询字符串 string sql = string.Format(select count(*) from Teacher where LoginId={0} and LoginPwd={1}, loginId, loginPwd); // 测试数据库连接 try { // 创建 Command 对象 SqlCommand


            {
                // 查询字符串
                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;
                } C#高职计算机导论考试系统设计与实现(17):http://www.youerw.com/jisuanji/lunwen_182.html
------分隔线----------------------------
推荐内容