Solved

Database - update a recold help please

Posted on 2004-09-21
3
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

624 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