Searching Database using LINQ
I have a database table (Access Database) that contains data under OrderNo field. When user enters new OrderNo, I want to check if that O开发者_开发技巧rderNo already exists or not. If so, a message should be displayed.
How can I do it using LINQ? Thanks Furqan
You could do something like this:
int searchOrderNo;
searchOrderNo = 123;
var q = from t in db.MyTable
where t.OrderNo.Equals(searchOrderNo)
select t.OrderNo;
if (q.Count() > 0)
{
MessageBox.Show("Value already exists");
}
Apologies, as you are using Access I think you will need to populate a DataSet and then use LINQ over the DataSet rather than querying the Access DB directly.
精彩评论