EDIT: Updated based on additional information from your other posts ...
Your getData method returns an IQueryable instead of a strongly typed result, so you end up casting it. Try changing it to:
public IQueryable<ORM_Linq.Articu> getData(...)
Are you trying to query "Articu" from different tables?
With the above change, your code can be rewritten as follows:
ORM_Linq.Articu result = mydata.SingleOrDefault(); if (result != null) { TextBoxCode.Text = result.id.ToString(); TextBoxName.Text = result.descrip; }
If you have one result, use
SingleOrDefault , which will return the default value if the results are not returned:
var result = mydata.SingleOrDefault(); if (result != null) { textbox1.text = result.ProductName;
If you have several results, then iterate over them:
foreach (var item in mydata) { string name = item.ProductName; int id = item.ProductId;
Ahmad mageed
source share