Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Database - update a recold help please

Posted on 2004-09-21
3
Medium Priority
?
154 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 375 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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