My code :
int key = 0;
//get primary key of inserted row
key = db.Query("SELECT max(event_id) FROM event where title=" + cevent.title + "AND description=" + cevent.description + "AND event_start=" + cevent.start + "AND event_end=" + cevent.end);
Error message :
Cannot implicitly convert type
‘System.Collections.Generic.IEnumerable’ to ‘int’
I am using C#, WebMatrix and SQL Server. WebMatrix. If I try and run ExecuteScalar instead of Query, I get
‘WebMatrix.Data.Database’ does not contain a definition for
‘ExecuteScalar’
Does anyone know what I can do to fix my code?
It sounds like you want
Database.QueryValueinstead.And as in your previous question, you should absolutely not be embedding the query parameter values within the SQL.
Database.QueryValueis documented as:… which sounds exactly right to me. It would be worth browsing through the docs – they’re not very detailed, but it would at least show you what’s available.