提问人:Iman Amien 提问时间:11/2/2022 最后编辑:Iman Amien 更新时间:11/3/2022 访问量:314
数据集未处于编辑或插入模式
Dataset not in edit or insert mode
问:
我是堆栈溢出的新用户。我有一个大项目即将到来,但我总是遇到同样的错误。我正在尝试将数据加载到我的数据库中,无论我尝试多少次或更改什么,我仍然会遇到相同的错误。我已经标记了nessarry变量,尝试了tbl()。Edit 和 tbl()。在我的循环内部、外部和 case 语句中插入,但我似乎仍然遇到同样的错误。
sPlayer1、sPlayer2、iScore1、iScore2 是全局变量。 `
procedure TfrmInvigilator.btnSubmitClick(Sender: TObject);
Var
i, j, iRound: Integer;
begin
sPlayer1 := cmbName1.Text; // Assigning values to variables for cmbPlayers
sPlayer2 := cmbName2.Text;
iScore1 := sedScore1.Value; // Assigning values to variables for sedScores
iScore2 := sedScore2.Value;
iRound := cmbRound.ItemIndex; // Assigning values to variable for cmbRound
if (cmbName1.ItemIndex = -1) then
// Displays show message if cbmName1 is blank
begin
ShowMessage('Please select player name');
end
else
begin // If cbmName1 is not blank then:
i := pos(' ', sPlayer1); // Find position of ' ' in cbmName1.Text
sPlayer1 := Copy(sPlayer1, 1, i - 1); // sPlayer1 := Name of player
dmChess.tblPlayerInfo.Locate('Name', sPlayer1, []); // Locates Name in table
Num1 := dmChess.tblPlayerInfo['ID']; // Retrives ID of player
with dmChess do
begin
tblScoreboard.First;
while NOT tblScoreboard.EOF do
begin
tblScoreboard.Locate('ID', Num1, []);
case iRound of
0:
tblScoreboard['Round 1A'] := iScore1;
1:
tblScoreboard['Round 1B'] := iScore1;
2:
tblScoreboard['Round 1C'] := iScore1;
3:
tblScoreboard['Round 1D'] := iScore1;
4:
tblScoreboard['Round 2'] := iScore1;
5:
tblScoreboard['Semi-Final'] := iScore1;
6:
tblScoreboard['Final'] := iScore1;
end;
tblScoreboard.Post;
end;
end;
end;
if (cmbName2.ItemIndex = -1) then
// Displays show message if cbmName2 is blank
begin
ShowMessage('Please slecet player name');
end
else
begin // If cbmName2 is not blank then:
j := pos(' ', sPlayer2); // Find position of ' ' in cbmName2.Text
sPlayer2 := Copy(sPlayer2, 1, j - 1); // sPlayer2 := Name of player
dmChess.tblPlayerInfo.Locate('Name', sPlayer2, []); // Locates Name in table
Num1 := dmChess.tblPlayerInfo['ID']; // Retrives ID of player
end;
end;
`
答:
3赞
Softacom
11/3/2022
#1
不能只在(表或查询)中设置新值,DataSet 必须知道要更改当前记录或插入新记录。一个异常告诉你这一点。解决方法:在对数据集中的任何字段进行更改之前,需要设置所需的模式。 - 编辑当前记录, - 在当前位置插入新记录, - 在末尾添加新记录。对于此代码片段,在行后添加行 - 将当前更改保存到记录中,并将数据集模式更改回“浏览”DataSet field
DataSet.edit;
DataSet.Insert
DataSet.Append
tblScoreboard.Edit;
tblScoreboard.Locate('ID', Num1, []);
DataSet.Post
评论
tblScoreBoard.edit
tblScoreboard.Post;
tblScoreboard.Edit;
tblScoreboard.Insert;