What is the most efficient method of declaring a sql statement at the top of the page:
@{
var db = Database.Open("database");
int id=anynumber;
var sql = ?
if(id==1){
sql = db.QuerySingle("select * from table where myid=@0", 5);
}
if(id==2){
sql = db.QuerySingle("select * from table where myid=@0", 6);
}
@sql.myid
}
'WebMatrix.Data.DynamicRecord' does not contain a definition for 'myid' accepting a first argument of type 'WebMatrix.Data.DynamicRecord' could be found (are you missing a using directive or an assembly reference?)
Member
107 Points
297 Posts
Declare sql statement
Jun 19, 2013 11:50 AM|engcanada|LINK
What is the most efficient method of declaring a sql statement at the top of the page:
All-Star
193991 Points
28021 Posts
Moderator
Re: Declare sql statement
Jun 19, 2013 12:27 PM|Mikesdotnetting|LINK
DynamicRecord sql = null;
Member
107 Points
297 Posts
Re: Declare sql statement
Jun 19, 2013 01:52 PM|engcanada|LINK
It produces the following error:
'WebMatrix.Data.DynamicRecord' does not contain a definition for 'myid' accepting a first argument of type 'WebMatrix.Data.DynamicRecord' could be found (are you missing a using directive or an assembly reference?)
All-Star
193991 Points
28021 Posts
Moderator
Re: Declare sql statement
Jun 19, 2013 03:55 PM|Mikesdotnetting|LINK
dynamic sql = null;
You still need to check to make sure that sql is not null before attempting to render sql.myId:
Member
107 Points
297 Posts
Re: Declare sql statement
Jun 19, 2013 04:28 PM|engcanada|LINK
Thank you Mike,
Your previous solution DynamicRecord sql = null; was the one that produced the error.
The latter solution dynamic sql = null; worked perfectly!
Regards