Link to home
Start Free TrialLog in
Avatar of jennifere
jennifere

asked on

Post data to a table

I am trying to post data and update a table as I am running through a loop.  I have already done table.edit and table.post.  However, when the loop gets to table.post, it displays an error message that says my dataset is not in edit or insert mode.  Is there a way to post data to a table each time my program executes through a loop??

while not (tblAgents.Eof) and (x < 51) do
begin
  edtSearch.Text := 'SHAFERJO';
  tblAgents.SQL.Clear;
  tblAgents.SQL.Add('Select * from Agents where AgentId = '+QuotedStr( startHere ) );
  tblAgents.Active := True;
  strEmail := tblAgents.fieldbyname('Email').AsString;
  strAgentId := tblAgents.fieldbyname('AgentId').AsString;
  strEmailStatus := tblAgents.fieldbyname('EmailStatus').AsString;
  strVerifiedDate := tblAgents.fieldbyName('EmailVerified').AsDateTime;
 
  if (x = 50) then
    if (strEmail <> '') then
    begin
       //Validate to SMTP level
        iRating := con.Validate(strEmail, hexVeLevelSmtp);

        //If address is bad
        if (hexVeLevelBad = iRating) then
        begin
          error := GetErrorString(con.Error);
          if (strEmailStatus = '1') then
             tblAgents.Fieldbyname('EmailStatus').AsString := '2';
          if (strEmailStatus = '2') then
             tblAgents.FieldByName('EmailStatus').AsString := 'I';

        //Address is good
        else
           tblAgents.FieldByName('EmailStatus').AsString := 'V';
       
        tblAgents.Edit;
        tblAgents.Post;
    end;
    tblAgents.Next;
    x := x + 1;
end;
 
ASKER CERTIFIED SOLUTION
Avatar of shaneholmes
shaneholmes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
while not (tblAgents.Eof) and (x < 51) do
begin
  edtSearch.Text := 'SHAFERJO';
  tblAgents.SQL.Clear;
  tblAgents.SQL.Add('Select * from Agents where AgentId = '+QuotedStr( startHere ) );
  tblAgents.Active := True;
  strEmail := tblAgents.fieldbyname('Email').AsString;
  strAgentId := tblAgents.fieldbyname('AgentId').AsString;
  strEmailStatus := tblAgents.fieldbyname('EmailStatus').AsString;
  strVerifiedDate := tblAgents.fieldbyName('EmailVerified').AsDateTime;
 
  if (x = 50) then
    if (strEmail <> '') then
    begin
        tblAgents.Edit;
       
       //Validate to SMTP level
        iRating := con.Validate(strEmail, hexVeLevelSmtp);

        //If address is bad
        if (hexVeLevelBad = iRating) then
        begin
          error := GetErrorString(con.Error);
          if (strEmailStatus = '1') then
             tblAgents.Fieldbyname('EmailStatus').AsString := '2';
          if (strEmailStatus = '2') then
             tblAgents.FieldByName('EmailStatus').AsString := 'I';

        //Address is good
        else
           tblAgents.FieldByName('EmailStatus').AsString := 'V';
       
        tblAgents.Post;
    end;
    tblAgents.Next;
    x := x + 1;
end;
Avatar of jennifere
jennifere

ASKER

Of course...  that makes sense.  Thanks-- and sorry for the stupid question.  :)
NP - remember - no question is stupid question? We have all made those mistakes!

Shane