bugfix: GetStudentByDbID where dbid_in < 1 should return null.
This commit is contained in:
parent
73f5a5a5e1
commit
93dd961a30
@ -54,10 +54,17 @@ namespace DBWizard
|
|||||||
*/
|
*/
|
||||||
public Student GetStudentByDbID(int dbid_in)
|
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()))
|
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
||||||
{
|
{
|
||||||
string strQuery = "SELECT * FROM students WHERE id=@id";
|
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;
|
return stu_out;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user