Solved

Post data to a table

Posted on 2004-04-05
4
222 Views
Last Modified: 2010-04-05
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;
 
0
Comment
Question by:jennifere
[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
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 250 total points
ID: 10758380
You need to do you assign staements after the tblAgents.Edit;

example


tblAgents.Edit;

        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;


Shane
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10758468
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;
0
 

Author Comment

by:jennifere
ID: 10758494
Of course...  that makes sense.  Thanks-- and sorry for the stupid question.  :)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10758539
NP - remember - no question is stupid question? We have all made those mistakes!

Shane
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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