Delphi 7 Ado Dataset not in edit or insert mode
I'm doing a little program in Delphi 7 with Access (I know it's old stuff). But it is giving the error when I try to record in a very simple thing.
tblPerguntas.Open;
tblPerguntas.Insert;
tblPerguntaspergunta.Value := edtPergunta.Text;
tblPerguntasControle.Value := 0;
tblPerguntasArquivo.value := edtMusica.Text;
tblRespostasResposta.Value := edtCerta.text;
tblPerguntas.Post;
Where am I going wrong? Remembering that the table tblPerguntas
with field ID
is auto numbering.
2
2 answers
As stated earlier the error is because the table is not in edit or insert mode following is the change in the Code:
//inicio do seu código tblPerguntas.Open; tblPerguntas.Insert; //coloque a tabela em modo de edição tblPerguntas.edit; tblPerguntaspergunta.Value := edtPergunta.Text; tblPerguntasControle.Value := 0; tblPerguntasArquivo.value := edtMusica.Text; tblRespostasResposta.Value := edtCerta.text; tblPerguntas.Post;
1
Author: Deivis Fontes, 2017-01-20 11:40:23
Since this error occurs when your table is not in insert or edit mode, check the state of the table before saving. See:
// Faltou Definir a forma de Edição / Inclusão para
// a Tabela tblRespostas
//
tblRespostas.Open;
tblPerguntas.Open;
Try
tblRespostas.Insert;
tblPerguntas.Insert;
// Importante verificar, pois pode ocorrer algum erro antes
// da atribuição dos valores aos campos.
// Ex: Erro em OnOpen, OnNewRecord, OnConnect Etc.
//
If ( tblRespostas.State In [ dsInsert, dsEdit ] ) And
( tblPerguntas.State In [ dsInsert, dsEdit ] ) Then
Begin
tblPerguntaspergunta.Value := edtPergunta.Text;
tblPerguntasControle.Value := 0;
tblPerguntasArquivo.value := edtMusica.Text;
tblRespostasResposta.Value := edtCerta.text;
tblPerguntas.Post;
tblRespostas.Post; // Inclua esta tabela tambem
End;
Finally
tblRespostas.Close;
tblPerguntas.Close;
End;
Do not forget to declare " DB " in the Uses clause.
0
Author: Oscar B Jr, 2015-03-05 19:55:07