我有一个带有值的 sql 数据库。我想用我输入的值交叉检查它,如果数据库中不存在该值,程序会返回一条自定义错误消息。我该怎么做呢?
这是代码:
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr != null)
{
if (dr.Read())
{
var student = new StudentParticulars
{
StudentName = dr.GetString(1),
SClass = dr.GetString(2),
SNRIC = dr.GetString(3),
FixedAmount = dr.GetDouble(4),
};
studentList.Add(student);
}
return studentList;
}
else
{
if (dr == null)
{
var student = new StudentParticulars
{
StudentName ="",
SClass = "",
SNRIC = "0",
};
}
return studentList;
}
}