Hello! I need to make login in Delphi 2010. I have MS Access database where I have fields (loginID, username, password). So I have 2 TEdit components for username and password. I have connected to database in delphi and all connections are working.
So problem is that I don't know how to check if text from TEdit is in database. I need something like query.
if Edit1.Text in login.username then
ADOQuery1.SQL.Text := 'SELECT FROM login WHERE username = :Edit1.Text';
if ADOQuery1 execute then
You need to properly parameterize your query, and use the Parameters. (You also need to write valid SQL, which for a SELECT requires a list of columns you want returned.)
ADOQuery1.SQL.Text := 'SELECT UserName FROM login WHERE username = :User'; ADOQuery1.Parameters.ParamByName('User').Value := Edit1.Text;
You then need to open (not execute) the query, and see if it returned a value.
ADOQuery1.Open; if not ADOQuery1.IsEmpty then begin // User exists. Do whatever you need next. end else // Do what you want if user not found
I'd strongly suggest that if you're going to try and use databases, you buy a book or find a tutorial.
SELECT is one of the most basic operations you'll need to perform.