Solved

Post data to a table

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

623 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