Search if a value exist in Service-Based Database in C# using LINQ

Viewed 62

I have made a textbox for user to enter id and I want to see if it exists in my table or not

HotelDatabaseDataContext db = new HotelDatabaseDataContext();//database 

customer_id = int.Parse(textBox1.Text);//value from textbox
var selected = from x in db.Customers
               where x.Id == customer_id//selecting value from database
               select x; 

/* I want to see if "selected" is null or not and want to store it's value in another variable */
if(selected.id==null)
{
    int _id = selected.id;
}
1 Answers
Related