当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteDatabase.ExecuteScalar方法代码示例

本文整理汇总了C#中SQLiteDatabase.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteDatabase.ExecuteScalar方法的具体用法?C# SQLiteDatabase.ExecuteScalar怎么用?C# SQLiteDatabase.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.ExecuteScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkAccount

        /// <summary>
        ///     Checks whether a specified account exists and whether the password supplied
        ///     is correct
        /// </summary>
        /// <param name="id">The ID of the student/teacher - Corresponds to the id field
        /// in the DB</param>
        /// <param name="pass">The password to check as a string</param>
        /// <param name="stuteach">A string containing "students" or "teachers"</param>
        /// <returns>true when account is correct, false otherwise</returns>
        public static bool checkAccount(int id, string pass, string stuteach)
        {
            SQLiteDatabase db = new SQLiteDatabase();
            string dbPass = db.ExecuteScalar(string.Format("SELECT hash FROM {0} WHERE id={1};", stuteach, id));
            string passHash = Password.hashAsString(pass);

            if (dbPass == passHash)
                return true;

            return false;
        }
开发者ID:notexactlyawe,项目名称:SpellingBee,代码行数:20,代码来源:AccountControl.cs

示例2: addStudent

        /// <summary>
        ///     Adds a student to the system
        /// </summary>
        /// <param name="name">The student's full name</param>
        /// <param name="pass">The student's password</param>
        /// <param name="stuClass">The student's class</param>
        public static void addStudent(string name, string pass, string stuClass)
        {
            /* The following variables are
             * db        - Instance of the SQLiteDatabase class
             * hash      - The SHA-256 hash of the password to be added as a string
             * added     - Used to avoid a bug with adding students if one has been deleted
             * attempts  - See above
             * studentID - The ID of the student to be added
             */
            SQLiteDatabase db = new SQLiteDatabase();
            string hash       = Password.hashAsString(pass);
            bool added        = false;
            int attempts      = 0;
            int studentID     = Convert.ToInt16(db.ExecuteScalar("SELECT id FROM students ORDER BY id DESC")) + 1;

            // While the db call hasn't executed
            while (!added)
            {
                try
                {
                    db.ExecuteNonQuery(string.Format("INSERT INTO students VALUES ({0}, \"{1}\", \"{2}\", \"{3}\");",
                        studentID, name, stuClass, hash));
                    added = true;
                }
                // Checks the number of attempts and if they're less than 10 it adds one to the studentID
                catch
                {
                    if (attempts > 9)
                    {
                        throw new Exception("Too many attempts");
                    }
                    studentID++;
                    attempts++;
                }
            }
        }
开发者ID:notexactlyawe,项目名称:SpellingBee,代码行数:42,代码来源:AccountControl.cs


注:本文中的SQLiteDatabase.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。