Solved

Database - update a recold help please

Posted on 2004-09-21
3
150 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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