bugfix: GetStudentByDbID where dbid_in < 1 should return null.

This commit is contained in:
kougyokugentou 2020-05-09 21:50:24 -07:00
parent 73f5a5a5e1
commit 93dd961a30
1 changed files with 8 additions and 1 deletions

View File

@ -54,10 +54,17 @@ namespace DBWizard
*/
public Student GetStudentByDbID(int dbid_in)
{
/* protect query from 0 or negative indexes.
* this is needed when creating a new student
* as dbid_in will be zero.
*/
if (dbid_in < 1)
return null;
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
string strQuery = "SELECT * FROM students WHERE id=@id";
var stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).Single();
Student stu_out = cnn.Query<Student>(strQuery, new { id = dbid_in }).Single();
return stu_out;
}