I have an if statement which checks whether or not an entry exists in my DB. The code correctly checks if an email address is already present, however if the email does not exist i get an error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding
on a null reference at CallSite.Target(Closure , CallSite , Object ) at
ASP._Page__footer_cshtml.Execute()
But if i remove the code that gets the existing email, these lines:
var getrecord = db.QuerySingle("Select Email from Registrations where email = @0", email);
emailexists = getrecord.email;
the data is saved back to the DB with no problems. Not sure if its because i'm using the same Db helper?
try
{
var db = Database.Open("MiniDB");
var getrecord = db.QuerySingle("Select Email from Registrations where email = @0", email);
emailexists = getrecord.email;
if (emailexists != ""){
msg = "This Email address is already registed";
saved = false;
}
else {
var insertCommand = "INSERT INTO Registrations (Email, Name, regDate) VALUES(@0, @1, @2)";
db.Execute(insertCommand, email, name, regDate);
saved = true;
}
}
catch (Exception ex)
{
msg = ex.ToString();
saved = false;
}