Solved

Database - update a recold help please

Posted on 2004-09-21
3
144 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
Comment Utility
what kind of DB ?
0
 
LVL 6

Accepted Solution

by:
bpana earned 125 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now