本文整理汇总了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;
}
示例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++;
}
}
}