Solved

Dataset not in insert or edit mode

Posted on 2001-08-26
6
1,829 Views
Last Modified: 2012-05-04
Here come some easy points to earn.

I have three tables, table1, table2 and table3.
Table2 have table1 as master.
Table3 is connected to the same database table as table1. I use table3 to look up information from the same database as table1 to add to table2.

Fields in table1 are:
ArtNo
Name

Fields in table2 are:
ArtNo
Pos
SubArtNo

My issue is to insert data from table1 into table2 in order to create a data structure.
The strange thing is that I recive a run time error when executing "Table2.Insert". The message is "Datasource is not in Insert or Edit mode".
How can I recive that message when puting the table in Insert mode??

Thanks in advance for your help.
0
Comment
Question by:dikonsult
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:God_Ares
Comment Utility
db.Insert; //turns some sort of switch
db.Fields.Fields[1].AsInteger := Finteger;
db.Fields.Fields[2].AsString := Fstring;
db.Post;
//No further comments
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
guessing you have table2 pushed in the edit-mode with table2.insert, but you will modify the table1.fields

review your code
0
 

Author Comment

by:dikonsult
Comment Utility
Kretzschmar,
nothing much about the code, quite similar to what God Ares proposed as an answer !!

procedure TFormMain.BitBtn3Click(Sender: TObject);
var
   i:integer;
begin
with Datamodule2 do
begin
  i:=Table2.RecordCount+1;
  Table2.Insert;
  Table2Pos.AsInteger:=i;
  Table2SubArtNo.Value:=Table3ArtNr.Value;
  Table2.Post;
end;
end;

Table2.Mastersource = Table1Datasource with masterFields = ArtNo.
Table3 is connected to the same TableName as Table1.

The error message comes at the line TableStrukreg.Insert.

The funny thing is that a new record actually is created in the table but my values are not added only the connection value ArtNo wich it recives from table1.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
are there more ttable instances named table2?

maybe this change resolves the problem

 i:=Datamodule2.Table2.RecordCount+1;
 Datamodule2.Table2.Insert;
 Datamodule2.Table2.FieldByName('Pos').AsInteger:=i;
 Datamodule2.Table2.FieldByName('SubArtNo').Value:=Table3ArtNr.Value;
 Datamodule2.Table2.Post;

0
 

Author Comment

by:dikonsult
Comment Utility
No kretschmar it did not help.
But now in pure desperation I removed the tables and created them again with same names and same connections. Suddenly it worked ????
Please send me an answer and you will recive the points as the one really trying.

Regards
dikonsult
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
Comment Utility
well,

then i guess,
there was something mixed with the persistent fields, maybe

glad that you get it work,
even if i was not a real help,
which pointed out the problem

meikl ;-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

18 Experts available now in Live!

Get 1:1 Help Now