Solved

Database - update a recold help please

Posted on 2004-09-21
3
147 Views
Last Modified: 2010-04-05
Hi there, am having problems with a database program i am doing. Database stuff is new to me.

I have a DB with a few filds in it i read as below
Fid.Text := adoquery.FieldByName('DepartmentID').AsString;

there is also a memo in the database i read like below
Fmemo.Lines.Text := adoquery.FieldByName('ClockDetails').AsString;

Now i can read any details ok from the selected recold. That works everytime without fail.

But i am not sure how to modify the recold.

To insert a new recold i use the below.

procedure TMain.AddNewUser(User, TheTime: string);
begin
 clear;
 with DataMod do
  begin
   with ADOTable do
    begin
     Close;
     Open;                                                                      
     Fmemo.Lines.Add('1 ' + TheTime);
     Insert;                                                                  
     FieldByName('ClockName').AsString := trim(lowercase(User));                
     FieldByName('ClockDetails').AsString := '1 ' + TheTime;                    
     FieldByName('InOrOut').AsBoolean := TRUE;                                  
     Post;                                                                      
     Close;                                                                      
    end;
  end;
end;


Now that works every time to post NEW data to the database.

I use the below to see if a recold is in the database or not.


function CheckDB(DATA, DATA2: string): Boolean;
var
 SQLString: string;
begin
{ DATA : Key name in database   }
{ DATA2: string to find         }
{ Return true if present        }
 with DataMod do
  begin
   ADOQuery.Close;
   ADOQuery.SQL.Clear;
   SQLString := 'select * from Employees where ' + DATA + ' = ' + #39 + DATA2 + #39;
   ADOQuery.SQL.Add(SQLString);
   ADOQuery.open;
   if ADOQuery.RecordCount < 1 then
    Result := False
   else
    Result := True;
   ADOQuery.Close;
  end;
end;

What i need to know is how can i update a recold if its already in the database.

Sorry if it seems a simple question about insert or edit, but like i said its all new to me and i am not to sure were it would have to go. :)
Nice if you could do a example to show me how to modify the recold and save it back again with comments so i can understand it :)


Cheers all.
0
Comment
Question by:satmanuk
3 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12115793
what kind of DB ?
0
 
LVL 6

Accepted Solution

by:
bpana earned 125 total points
ID: 12117757
you should position to the record which you want to update. it is similar to the insert procedure. you just have to use Edit in place of Insert.

Here's an example:

procedure TMain.ModifyUser(User, TheTime: string);
begin
 with DataMod do
  begin
   with ADOTable do
    begin
     Edit;                                                                  
     FieldByName('ClockName').AsString := trim(lowercase(User));                
     FieldByName('ClockDetails').AsString := '1 ' + TheTime;                    
     FieldByName('InOrOut').AsBoolean := TRUE;                                  
     Post;                                                                      
     Close;                                                                      
    end;
  end;
end;

Bogdan
0
 
LVL 11

Expert Comment

by:calinutz
ID: 12118255
This one updates the record that is identified by the DATA - key name, setting ClockName field to the value  of DATA2

Procedure MyUpdateSql(DATA, DATA2: string);
var
 SQLString: string;
begin
{ DATA : Key name in database   }
   ADOQuery.Active:=false;
   ADOQuery.SQL.Clear;
   SQLString := 'UPDATE employees set ClockName='+QuotedStr(DATA2)+' where DATA = ' +DATA ;
   ADOQuery.SQL.Add(SQLString);
   ADOQuery.ExecSQL;
end;
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question