Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2017, 04:13 PM
sktamrkar sktamrkar is offline
Member
 
Join Date: Oct 2013
Posts: 71
Default SQL table search

Hi experts, i am creating a login window with user name and password. The user name and password are stored in a sql database table. I put ado control connect it with sql table. On button click, username and password are searched in sql table. Plz peovide me code to search in sql table. Before i work with ms access database and success to get desire result. I never used sql, so help me how to search in sql table.



Thnx
Sandeep kumar
Reply With Quote
  #2  
Old 02-08-2017, 11:33 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 314
Default

Once the file is opened, use the Delphi Command LOCATE. See Delphi Help.

This will place you on the record containing the match.

Cheers Wallace
Reply With Quote
  #3  
Old 02-09-2017, 03:24 AM
sktamrkar sktamrkar is offline
Member
 
Join Date: Oct 2013
Posts: 71
Default

Quote:
Originally Posted by Marsheng View Post
Once the file is opened, use the Delphi Command LOCATE. See Delphi Help.

This will place you on the record containing the match.

Cheers Wallace

Sir Marsheng, if u have a code for guide me plz provide. I have searched delphi help, but fail.


Thnx
Sandeep Kumar
Reply With Quote
  #4  
Old 02-09-2017, 07:31 AM
Jasser Jasser is online now
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

How about using TADOQuery to search the data. Use the below SQL clause inside the TADOQuery :

Code:
SELECT UserName, PassWord FROM TheTableName WHERE UserName = :TheUserNameThatWasEntered
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #5  
Old 02-09-2017, 07:38 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 314
Default

Do you have a CONNECTION, TABLE and DATASOURCE setup as yet ?

Which SQL are you using ?
Reply With Quote
  #6  
Old 02-09-2017, 08:02 AM
sktamrkar sktamrkar is offline
Member
 
Join Date: Oct 2013
Posts: 71
Default

Thnx jessar sir, i will try and post result.
Reply With Quote
  #7  
Old 02-09-2017, 08:03 AM
sktamrkar sktamrkar is offline
Member
 
Join Date: Oct 2013
Posts: 71
Default

Quote:
Originally Posted by Marsheng View Post
Do you have a CONNECTION, TABLE and DATASOURCE setup as yet ?

Which SQL are you using ?
Yes, i am using sql management studio[mysql].
Reply With Quote
  #8  
Old 02-09-2017, 09:23 AM
dnattack dnattack is offline
Junior Member
 
Join Date: Jan 2017
Posts: 2
Default

Something like this?



Code:
 
Function TMyForm.Login: Boolean;
Label
   START_LOGIN;
Var
   _USER, _PASS: String;
Begin
   Result := False;
 
   // Database access with predetermined credentials
   Try
      AdoDB.Open;
   Except
      On E: Exception Do
      Begin
         ShowMsg('Can''t connect to database server!' + #13#10 +
                 'Application will be terminated...'  + #13#10 + #13#10 +
                 E.Message);
         Application.Terminate;
      End;
   End;
 
 
   // login cycle
   START_LOGIN:
 
 
   // Get username and password from a modal window
   Application.ProcessMessages;
   If (FPoloLogin.ShowModal <> MrOk) Then
   Begin
      Application.Terminate;
      Exit;
   End;
 
   _USER := FPoloLogin._Res_User;
   _PASS := FPoloLogin._Res_Pass;
 
 
   // Get user information
   If QUsers.Active Then QUsers.Close;
 
   QUsers.SQL.Text :=
      'Select From USERS Where'               + #13#10 +
      '   (UserName = ''' + _USER + ''') And' + #13#10 +
      '   (Password = ''' + _PASS + ''')';
 
   Try
      QUsers.Open;
   Except
      On E: Exception Do
      Begin
         ShowMsg('Can''t open Users information table!' + #13#10 +
                  'Application will be terminated...'   + #13#10 + #13#10 +
                 E.Message);
         Application.Terminate;
      End;
   End;
 
   If (QUsers.RecordCount < 1) Then // some dbs return -1, some db 0
   Begin
      ShowMsg('Username or Password invalid!' + #13#10 +
              'Please retry...');
 
      // Restart cycle
      Goto START_LOGIN;
   End
   Else
   Begin
      // If needed get other user info
 
      ShowMsg('Login succesful!');
   End;
 
   QUsers.Close;
 
   Result := True;
End;
Reply With Quote
  #9  
Old 02-09-2017, 10:15 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default

@dnattack
In Delphi a goto is possible but is an absolute NO!!!!
It's not Visual Basic code, so try to get that out of your system as quick as possible.
Reply With Quote
  #10  
Old 02-15-2017, 02:43 AM
lexd lexd is offline
Senior Member
 
Join Date: Feb 2015
Posts: 268
Default

People are not reading your question correctly

Hi experts, i am creating a login window with user name and password. The user name and password are stored in a sql database table.
You need to read up on the SQL language
https://www.w3schools.com/sql/

ADO is easy to use with MS Access and good for learning purposes
ADO is getting less and less windows support from windows, try and use OBDC if you can use it with your Delphi.

You will set up a table {hide it from form} and link it to your table
The data set will hold your query result
you can use the word Insert to insert new record to the a table.
And then can update the fields and read stuff as you move through the records. So you can use Delphi code or use SQL to do the search for you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.