Solved

Post data to a table

Posted on 2004-04-05
4
218 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now