title: C# Windows Forms Application textbox validation against SQL DB
body: <p>I'm new to C# and have a background in SQL so apologies if this is a very stupid query, but I have been trawling google for about 2 hours now and can't find what I need.  If someone knows of an article they can point me to, that would be great.</p>
  
  <p>I have a simple windows forms application, and I'm setting up a login box so that users have to enter their user ID to proceed.</p>
  
  <p>I have a SQL Server DB (SQL 2005) with the following table:</p>
  
  <p>Users
  UserID (int); userName nvarchar(50)</p>
  
  <p>I am using Visual Studio 2010</p>
  
  <p>What I'm stymied by is how to check whether their userID exists in my SQL Table (called users...)  I'm not going to put any code here because it's been rewritten from scratch so many times that a clean slate is probably best!</p>
  
  <p>Ideally, I want the user to enter their user ID, and click 'login'.  When they do this, if their userID is not valid in the DB table then I need it to give an error msgBox; if it is valid then it should log them in, passing their userID and userName (stored in the DB table) to a variable which I can use elsewhere in the application to populate fields.</p>
  
  <p>I hope this makes sense, and I'm sure I've missed the perfect article out there which will explain it all - hopefully one of you kind people can point me in the right direction!</p>
  
  <p>Thank you</p>