Solved

Post data to a table

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 76
Working with hours 3 65
Tembedded WB animatid gifs not animated on some pcs 2 84
How to insert .png images to TClientDataSet .cds file? 2 33
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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