Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-03-2010
aanil aanil is offline
Miembro
 
Registrado: abr 2006
Posts: 155
Poder: 21
aanil Va por buen camino
Hola.

Voy a probar eso que me dices:

Esta es la forma como lo tengo

Código Delphi [-]
procedure TForm3.BitBtn4Click(Sender: TObject);
begin

if radioButton1.Checked = true then
begin
   with datam.Query1 do begin;

close;
sql.Clear;

sql.Add('select NOMBRES,MATRICULA,CLAVE,A1 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
end;


if radioButton2.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A2 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;

end;
 end;

if radioButton3.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A3 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
 edit;

end;
 end;

 if radioButton4.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A4 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

 if radioButton5.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A5 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

if radioButton6.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A6 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

if radioButton7.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A7 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

if radioButton8.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A8 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

 if radioButton9.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES,MATRICULA,CLAVE,A9 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
 end;

 if radioButton10.Checked = true then
begin
   with datam.Query1 do begin;
close;
sql.Clear;
sql.Add('select NOMBRES, MATRICULA,CLAVE,A10 from 20092');
sql.Add('where clave ='+quotedstr(combobox1.Text));
sql.Add(   'order by nombres asc');
open;
edit;
end;
end;
end;

Y esta funcionando.

Lo que se ve es muy largo, pero eso es lo que tengo.

Saludos..
Responder Con Cita
  #2  
Antiguo 12-03-2010
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 28
Caral Va por buen camino
Hola
Sabiendo que la sentencia SQL es string se puede hacer casi cualquier cosa, un ejemplo:
Código Delphi [-]
procedure TForm3.BitBtn4Click(Sender: TObject);
var Texto: String;
begin
 Texto:= 'where clave = '+quotedstr(combobox1.Text)+' order by nombres asc';
 with datam.Query1 do begin;
 close;
 sql.Clear;

if radioButton1.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A1 from 20092'+Texto;
open;
edit;
end;

if radioButton2.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A2 from 20092'+Texto;
open;
edit;
end;

if radioButton3.Checked = true then
begin
sql.Text:='select NOMBRES,MATRICULA,CLAVE,A3 from 20092'+Texto;
open;
edit;
end;

if radioButton4.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A4 from 20092'+Texto;
open;
edit;
end;

if radioButton5.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A5 from 20092'+Texto;
open;
edit;
end;

if radioButton6.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A6 from 20092'+Texto;
open;
edit;
end;

if radioButton7.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A7 from 20092'+Texto;
open;
edit;
end;

if radioButton8.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A8 from 20092'+Texto;
open;
edit;
end;

if radioButton9.Checked = true then
begin
sql.Text:= 'select NOMBRES,MATRICULA,CLAVE,A9 from 20092'+Texto;
open;
edit;
end;

if radioButton10.Checked = true then
begin
sql.Text:= 'select NOMBRES, MATRICULA,CLAVE,A10 from 20092'+Texto;
open;
edit;
end;

end;
De esta manera no se repite el codigo constantemente.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #3  
Antiguo 12-03-2010
aanil aanil is offline
Miembro
 
Registrado: abr 2006
Posts: 155
Poder: 21
aanil Va por buen camino
Gracias Caral

Este código esta mas claro, comodo y bien comprensible.

Gracias..
Responder Con Cita
  #4  
Antiguo 12-03-2010
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 28
Caral Va por buen camino
Hola
Recuerda que en tu caso prácticamente todo se repite y que lo que necesitas modificar es solamente el string del SQL, osea, tienes muchas alternativas.
Otra, mas reducida:
Código Delphi [-]
procedure TForm3.BitBtn4Click(Sender: TObject);
var Texto1, Texto2: String;
begin
 Texto1:= 'select NOMBRES,MATRICULA,CLAVE,';
 Texto2:= 'from 20092 where clave = '+quotedstr(combobox1.Text)+' order by nombres asc';
 with datam.Query1 do begin;
 close;
 sql.Clear;

try
if radioButton1.Checked = true then
begin
sql.Text:= Texto1+'A1'+Texto2;
end;

if radioButton2.Checked = true then
begin
sql.Text:= Texto1+'A2'+Texto2;
end;

if radioButton3.Checked = true then
begin
sql.Text:= Texto1+'A3'+Texto2;
end;

if radioButton4.Checked = true then
begin
sql.Text:= Texto1+'A4'+Texto2;
end;

if radioButton5.Checked = true then
begin
sql.Text:= Texto1+'A5'+Texto2;
end;

if radioButton6.Checked = true then
begin
sql.Text:= Texto1+'A6'+Texto2;
end;

if radioButton7.Checked = true then
begin
sql.Text:= Texto1+'A7'+Texto2;
end;

if radioButton8.Checked = true then
begin
sql.Text:= Texto1+'A8'+Texto2;
end;

if radioButton9.Checked = true then
begin
sql.Text:= Texto1+'A9'+Texto2;
end;

if radioButton10.Checked = true then
begin
sql.Text:= Texto1+'A10'+Texto2;
end;

finally
open;
edit;
end;

end;

end.
Y habrán mas opciones, la idea con esto es solamente que aprendamos a dividir un string.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #5  
Antiguo 12-03-2010
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 28
Caral Va por buen camino
Hola
Se nota que no tengo nada que hacer jejeje.
Este codigo tal vez te parezca interesante, mira como se reduce todo:
Código Delphi [-]
procedure TForm3.BitBtn4Click(Sender: TObject);
var
Texto1, Texto2: String;
i: Integer;
Comp: TComponent;

begin
 Texto1:= 'select NOMBRES,MATRICULA,CLAVE,A';
 Texto2:= 'from 20092 where clave = '+quotedstr(combobox1.Text)+' order by nombres asc';
 with datam.Query1 do begin;
 close;
 sql.Clear;

 for i := 1 to 10 do begin  // 10 radioButton
 comp := FindComponent('radioButton' + IntToStr(i));

 If TradioButton(comp).Checked = true then
 begin
 sql.Text:= Texto1+IntToStr(i)+Texto2;
 open;
 edit;
 end;

end;
end;
end;
Siempre me acuerdo que el Maestro Neftali fue el que me lo enseño.
Saludos
__________________
Siempre Novato
Responder Con Cita
  #6  
Antiguo 13-03-2010
aanil aanil is offline
Miembro
 
Registrado: abr 2006
Posts: 155
Poder: 21
aanil Va por buen camino
Hola Caral.

El penúltimo código lo copie y pegue y cuando lo corro dice este mensaje de error.

s (falta operador) en la expresion de consulta 'A1from 20092 where clave = 'PED 411-04' orde by nombres asc'.

El ultimo código también presenta un error aun mas grave.

Saludos.
Responder Con Cita
  #7  
Antiguo 13-03-2010
Avatar de Caral
[Caral] Caral is offline
Miembro Premium
 
Registrado: ago 2006
Posts: 7.659
Poder: 28
Caral Va por buen camino
Hola
No veo donde esta el error, tal vez sea la separación:
Código Delphi [-]
sql.Text:= Texto1+' A1 '+Texto2;
No se....
Saludos
__________________
Siempre Novato
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Hacer que una columna de un DbGrid aparezca distinta según valor Aprendiendo OOP 11 30-11-2018 14:47:20
error de sql server "Informacion de columna clave insuficiente" jhcaboverde Conexión con bases de datos 1 17-08-2007 19:40:31
Informacion de columna clave insuficiente para realizar la operacion update o refresh Cabanyaler MS SQL Server 11 04-06-2007 13:25:04
informacion de columna clave insuficiente vipernet MS SQL Server 6 07-09-2006 20:26:40
Extraer datos de una pagina en java que tiene clave (sabiendo la clave claro) ;) kalimocho Internet 2 29-06-2005 05:11:24


La franja horaria es GMT +2. Ahora son las 18:30:29.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi