views:

602

answers:

1

I am using something like the above sample code but when i try to execute it, it says that the query syntax is wrong and there is an error in the query syntax near keyword into...

System.Data.Objects.ObjectParameter[] opc=new System.Data.Objects.ObjectParameter[1];
//just sample

opc[0]=new System.Data.Objects.ObjectParameter("columnname","columnvaluetoinsert")

string strQuery="insert into tablename(columnname)values(@columnname)";

var query1 = entities.CreateQuery(strQuery, opc);

query1.Execute(System.Data.Objects.MergeOption.NoTracking);

A: 

Now after more than four months or so I can answer this...

string tableName = "yourTableName";
string PrimaryColName = "PrimarykeyName";

using(Entities entities = new Entities) { string sQuery= " select value " + tableName + " from " + tableName + " as " + tableName;
sQuery += " where ";
sQuery += tableName + ".PrimaryColName " = " + lngMasterId;

System.Data.Objects.ObjectQuery query = new System.Data.Objects.ObjectQuery(sMasterTableName, entities);
//where entities is the object of your objectContext class :)
return query.First();//do whatever you want with the result
}

here "value" after the "select" tells to give the result in to the custom anonymous format

gaurav