tags:

views:

24

answers:

1

Hi, I have a database table (Access Database) that contains data under OrderNo field. When user enters new OrderNo, I want to check if that OrderNo already exists or not. If so, a message should be displayed.

How can I do it using LINQ? Thanks Furqan

A: 

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.

Barry
Thanks, Do I need to add any libraries? Also, how to give path of my database? Should it be in the folder where the application is running from?