Fórum Erro no DataReader #280323

05/05/2005

0

Delphi 2005 / ASP.net / MySQL

Galera estou com um problema neste código e nao sei como resolver, nem imagino onde esta o erro do código, acredito que tenha feito tudo certo, porém esta dando erro na hora de abrir a página.

Isso vai servir para um cadastro de palavras chaves, esta mesma página vai servir para cadastrar em tabelas diferentes
Execute failed. Commands out of sync; You can´t run this command now


Var
ID, Tabela, CampoID, CampoRelac, CampoChave : string;
{ Public Declarations }
end;

implementation

procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
Var
SQLCampos : BdpCommand;
DataCampos : BdpDataReader;
begin
ID := Request.QueryString[´id´];
Tabela := Request.QueryString[´tabela´];

{$REGION: ´CAPTURANDO NOME DE CAMPOS´}
SQLCampos := BdpCommand.Create(´SELECT * FROM ´ + Tabela, Connection);
try
Connection.Open();
DataCampos := SQLCampos.ExecuteReader();
CampoID := DataCampos.GetName(0);
CampoRelac := DataCampos.GetName(1);
CampoChave := DataCampos.GetName(2);
finally
Connection.Close();
end;
{$ENDREGION}

MostrarPalavra(); //EXIBE OS DADOS NA DATAGRID

end;

procedure TWebForm1.CVpalavra_ServerValidate(source: System.Object; args: System.Web.UI.WebControls.ServerValidateEventArgs);
Var
sqlvalidar : BdpCommand;
begin
sqlvalidar := BdpCommand.Create(´SELECT 1 FROM ´ + Tabela + ´ WHERE ´ + Tabela + ´_id = ´ + ID + ´ AND ´ + Tabela + ´_CHAVE = ´´ + txtpalavra.Text + ´´´, Connection);
try
Connection.Open();
args.IsValid := sqlvalidar.ExecuteScalar() = nil;
finally
Connection.Close();
end;
end;

procedure TWebForm1.btnconfirma_Click(sender: System.Object; e: System.EventArgs);
Var
sqlinserir : BdpCommand;
begin
if not Self.IsValid then Exit;
sqlinserir := BdpCommand.Create(´INSERT INTO palavra_noticia(´ + CampoRelac + ´, ´ + CampoChave + ´) VALUES (´ + ID + ´, ´ + txtpalavra.Text + ´)´, Connection);
try
Connection.Open();
sqlinserir.ExecuteNonQuery();
finally
Connection.Close();
end;
end;

procedure TWebForm1.MostrarPalavra;
Var
sqlpalavra : BdpDataReader;
commandpalavra : BdpCommand;
begin
commandpalavra := BdpCommand.Create(´SELECT * FROM ´ + Tabela + ´ WHERE ´ + CampoRelac + ´ = ´ + ID, Connection);
try
Connection.Open();
sqlpalavra := commandpalavra.ExecuteReader;
DGPalavra.DataSource := sqlpalavra;
DGPalavra.DataBind();
finally
Connection.Close();
end;
end;


Rzcoimbra

Rzcoimbra

Responder

Posts

06/05/2005

Rzcoimbra

qualquer coisa já ajuda


Responder

Gostei + 0

06/05/2005

Rjun

Em que linha ocorre o erro ?


Responder

Gostei + 0

06/05/2005

Rzcoimbra

Está dando erro lá embaixo na linha destacada, o erro está logo abaixo

Server Error in ´/WebApplication2´ Application.
--------------------------------------------------------------------------------

Execute failed. Commands out of sync; You can´t run this command now
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Borland.Data.Common.BdpException: Execute failed. Commands out of sync; You can´t run this command now

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.




Connection.Open();
****sqlpalavra := commandpalavra.ExecuteReader;
DGPalavra.DataSource := sqlpalavra;
DGPalavra.DataBind();


Responder

Gostei + 0

06/05/2005

Rjun

Connection.Open(); 
DataCampos := SQLCampos.ExecuteReader();  [1] <--
CampoID := DataCampos.GetName(0); 
CampoRelac := DataCampos.GetName(1); 
CampoChave := DataCampos.GetName(2); 
finally 
Connection.Close(); 
end; 
{$ENDREGION} 

MostrarPalavra(); //EXIBE OS DADOS NA DATAGRID 


Não teria q ter um [b:14fcf0a745]DataCampos.Read[/b:14fcf0a745] depois da linha [1]

Não esqueça que você deve dar um close do datareader para poder abrir outro na mesma conexão.


Responder

Gostei + 0

06/05/2005

Rzcoimbra

brigadao cara...

valeu. era isso mesmo. to iniciando ainda por isso deixo coisas bobas.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar