Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Sentencia Sql

Estas en el tema de Sentencia Sql en el foro de Visual Basic clásico en Foros del Web. hola necesito si alguien me puede ayudar con la sentencia sql ya q a mi no me funciona xq nunca he trabajado con esa sentencia ...
  #1 (permalink)  
Antiguo 06/08/2008, 14:07
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Sonrisa Sentencia Sql

hola
necesito si alguien me puede ayudar
con la sentencia sql
ya q a mi no me funciona xq nunca he trabajado con esa sentencia
lo que quiero es q me busq por la fecha

yo puse esto pero no me funciona

FILTRO = "SELECT * FROM ingresos WHERE Codigo ='' ORDER By Fecha"
Set RStingresos = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)

y otra cosa en q parte coloco este codigo
en un command? o en otra parte

porfa si alguien me pudiera ayudar
  #2 (permalink)  
Antiguo 06/08/2008, 14:19
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

Bueno si lo que quieres es buscar por una fecha que el usuario ingrese tienes que agregar un command que es el que te va hacer la busqueda y un caja de texto donde vas a ingresar la fecha.

en el command debes poner esto:
Código:
FILTRO = "SELECT * FROM ingresos WHERE Codigo = "# TuCajaTexto.Text #" ORDER BY Fecha"
Set RStingresos = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)
Y si lo que quieres que te busque por la fecha del sistemas de tu computadora usa esta
Código:
FILTRO = "SELECT * FROM ingresos WHERE Codigo = "# date #" ORDER BY Fecha"
Set RStingresos = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)

Espero te Sirva, Si no Nos dices para ayudarte.
  #3 (permalink)  
Antiguo 07/08/2008, 06:55
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

hola
oye

FILTRO = "SELECT * FROM ingresos WHERE Codigo = "# TuCajaTexto.Text #" ORDER BY Fecha"

en donde dice tucajatexto.text me sale error y le cambio por text30.text pero = me arroja error q hago?

otra cosa en donde va este otro codigo?

FILTRO = "SELECT * FROM ingresos WHERE Codigo = "# date #" ORDER BY Fecha"
Set RStingresos = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)

y muchas gracias x tu ayuda

ya q en otro foro
no me quisieron ayudar
he incluso se estuvieron burlando de mi

muchas gracias...
  #4 (permalink)  
Antiguo 07/08/2008, 07:34
 
Fecha de Ingreso: abril-2007
Mensajes: 140
Antigüedad: 17 años
Puntos: 3
Respuesta: Sentencia Sql

Hola, te completo lo que te menciono salomonsab. En realidad lo que tenes que escribir es asi:
FILTRO = "SELECT * FROM ingresos WHERE Codigo = #" & text30.text & "# ORDER BY Fecha"

Espero te sirva
  #5 (permalink)  
Antiguo 07/08/2008, 07:36
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

ooooooo, lo que paso es que te lo hice al vuelo entonces pruebalo asi:

Código:
FILTRO = "SELECT * FROM ingresos WHERE Codigo = #" & Format(text30.text , "mm/dd/yyyy") & "# ORDER BY Fecha", Tuconexion, adOpenStatic, adLockOptimistic 
Set RStingresos = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)
Y el segundo es por si quieres hacer una busqueda por la fecha de tu sistemas, que es lo mismo que te estoy colocando solo cambia la linea Text30.Text por Date y es todo.

Espero que ahora si acertemos. a otra cosa que se me paso tienes que colocarlo en el boton donde vas hacer la busqueda
  #6 (permalink)  
Antiguo 07/08/2008, 07:42
Avatar de Jhonnyf  
Fecha de Ingreso: septiembre-2007
Ubicación: Dentro de mi
Mensajes: 87
Antigüedad: 16 años, 7 meses
Puntos: 5
Respuesta: Sentencia Sql

Veo que usas DAO

suponiendo que ya hiciste las referencias....
aqui tengo una funcion que abre un archivo mdb, si hay error la funcion te devuelve false

Código:
Public Function OpenStudentDataBase() As Boolean
'Llamado en Form_Load

Dim MyDataFile As String
On Error GoTo Er:
MyOrderBYSQL = "ORDER BY LastName" 'Aqui pongo mi Order by
MyQuery = "SELECT * FROM Students "  'aqui la consulta 
MyDataFile = "C:\Fall 2002.mdb" 'Aqui la Base de datos

Set db = OpenDatabase(MyDataFile) 'Aqui Abro la BD

 Set rs = db.OpenRecordset(MyQuery & MyOrderBYSQL, dbOpenDynaset) 'Aqui hago la consulta

OpenStudentDataBase = True 'Si no hubo error, entonces devuelvo TRUE para indicar que todo fue OK
Exit Function
Er:
    MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
    OpenStudentDataBase = False 'Devuelvo Falso si algo salio mal al abrir
End Function

Sorry, pero saque el codigo de un programa antiguo que tenia por ahi, por eso el nombre de la funcion y demas :D

Si deseas, te subo ese programa, es bastante sencillo, se lo hize a un amigo que me pidio ese favor, lo tengo en ADO y en DAO
__________________
*en construccion*
  #7 (permalink)  
Antiguo 07/08/2008, 08:00
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

ok muchas gracias por todo
  #8 (permalink)  
Antiguo 07/08/2008, 08:06
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

me sigue saliendo error
  #9 (permalink)  
Antiguo 07/08/2008, 08:07
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

FILTRO = "SELECT * FROM ingresos WHERE Codigo = #" & Format(text30.text , "mm/dd/yyyy") & "# ORDER BY Fecha", Tuconexion, adOpenStatic, adLockOptimistic

en toda la linea

xq..................
  #10 (permalink)  
Antiguo 07/08/2008, 08:40
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

Quitale esto ultimo:
Código:
Tuconexion, adOpenStatic, adLockOptimistic
Si no te funciona pon el codigo donde haces tu consulta y la conexión para ayudarte.
  #11 (permalink)  
Antiguo 07/08/2008, 09:44
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Pregunta Respuesta: Sentencia Sql

ahora tengo otro error
q me sale en esta linea

Set RStingreso = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)

gracias x todo
  #12 (permalink)  
Antiguo 07/08/2008, 10:43
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

Bueno bueno, Tienes que tener estas referencias.

Dim DbTBE2 As DAO.Database
Dim RStingreso As DAO.Recordset

Tienes que abri tu Base de datos Asi
Código:
Set DbTBE2 = OpenDatabase(App.Path & "\TuBD.mdb", True, False, ";pwd=" & "TuPassword")
y ahora si hacer la consulta de esta forma:
Código:
Set RStingreso = DbTBE2.OpenRecordset("SELECT * FROM ingresos WHERE Codigo = #" & text30.text & "# ORDER BY Fecha")
Espero que ahora si te funcione, SI no sube el codigo para ayudarte.
  #13 (permalink)  
Antiguo 07/08/2008, 12:37
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Pregunta Respuesta: Sentencia Sql

Mejor te dejo todo mi codigo haber si puedes encontrar q es lo q esta mal


Dim TBE2 As Database
Dim reg As Recordset
Dim lista As ListItem
Dim DbTBE2 As DAO.Database
Dim RStingreso As DAO.Recordset

Private Sub Command1_Click()
reg.AddNew
reg!fecha = Text1.Text
reg!guia = Text2.Text
reg!proveedor = Text3.Text
reg!cantidad = Text4.Text
reg!devolucion = Text5.Text
reg!farmacia = text6.Text
reg!trapi = Text7.Text
reg!vivanco = Text8.Text
reg!crucero = Text9.Text
reg!cayurruca = Text10.Text
reg!mantilhue = Text11.Text
reg!futahuente = Text12.Text
reg!carimallin = Text13.Text
reg!sector1 = Text14.Text
reg!sector2 = Text15.Text
reg!sector3 = Text16.Text
reg!procedimiento = Text17.Text
reg!clinicasdentales1 = Text18.Text
reg!ira = Text19.Text
reg!era = Text20.Text
reg!salamotora = Text21.Text
reg!prestamos = Text22.Text
reg!saldo = Text23.Text
reg!inventario = Text24.Text
reg!clinicasdentales2 = Text25.Text
reg!clinicasdentales3 = Text26.Text
reg!clinicasdentales4 = Text27.Text
reg!codigo = Text28.Text
reg!medicamento = Text29.Text
reg.Update

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Text16.Text = ""
Text17.Text = ""
Text18.Text = ""
Text19.Text = ""
Text20.Text = ""
Text21.Text = ""
Text22.Text = ""
Text23.Text = ""
Text24.Text = ""
Text25.Text = ""
Text26.Text = ""
Text27.Text = ""
Text28.Text = ""
Text29.Text = ""

Text28.SetFocus

End Sub

Private Sub Command2_Click()
reg.Delete
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Text16.Text = ""
Text17.Text = ""
Text18.Text = ""
Text19.Text = ""
Text20.Text = ""
Text21.Text = ""
Text22.Text = ""
Text23.Text = ""
Text24.Text = ""
Text25.Text = ""
Text26.Text = ""
Text27.Text = ""
Text28.Text = ""
Text29.Text = ""

Text28.SetFocus
End Sub

Private Sub Command3_Click()
Text23.Text = Val(text6.Text) + Val(Text7.Text) + Val(Text8.Text) + Val(Text9.Text) + Val(Text10.Text) + Val(Text11.Text) + Val(Text12.Text) + Val(Text13.Text) + Val(Text14.Text) + Val(Text15.Text) + Val(Text16.Text) + Val(Text17.Text) + Val(Text18.Text) + Val(Text19.Text) + Val(Text20.Text) + Val(Text21.Text) + Val(Text22.Text) + Val(Text25.Text) + Val(Text26.Text) + Val(Text27.Text)

Text24.Text = Val(text6.Text) + Val(Text7.Text) + Val(Text8.Text) + Val(Text9.Text) + Val(Text10.Text) + Val(Text11.Text) + Val(Text12.Text) + Val(Text13.Text) + Val(Text14.Text) + Val(Text15.Text) + Val(Text16.Text) + Val(Text17.Text) + Val(Text18.Text) + Val(Text19.Text) + Val(Text20.Text) + Val(Text21.Text) + Val(Text22.Text) + Val(Text25.Text) + Val(Text26.Text) + Val(Text27.Text)

End Sub

Private Sub Command4_Click()
Text23.Text = Val(text6.Text) - Val(Text7.Text) - Val(Text8.Text) - Val(Text9.Text) - Val(Text10.Text) - Val(Text11.Text) - Val(Text12.Text) - Val(Text13.Text) - Val(Text14.Text) - Val(Text15.Text) - Val(Text16.Text) - Val(Text17.Text) - Val(Text18.Text) - Val(Text19.Text) - Val(Text20.Text) - Val(Text21.Text) - Val(Text22.Text) - Val(Text25.Text) - Val(Text26.Text) - Val(Text27.Text)

Text24.Text = Val(text6.Text) - Val(Text7.Text) - Val(Text8.Text) - Val(Text9.Text) - Val(Text10.Text) - Val(Text11.Text) - Val(Text12.Text) - Val(Text13.Text) - Val(Text14.Text) - Val(Text15.Text) - Val(Text16.Text) - Val(Text17.Text) - Val(Text18.Text) - Val(Text19.Text) - Val(Text20.Text) - Val(Text21.Text) - Val(Text22.Text) - Val(Text25.Text) - Val(Text26.Text) - Val(Text27.Text)

End Sub

Private Sub Command5_Click()
Unload Me
End Sub

Private Sub Command6_Click()
Data1.UpdateRecord
End Sub

Private Sub Command7_Click()
FILTRO = "SELECT * FROM ingresos WHERE Codigo = #" & Format(Text30.Text, "mm/dd/yyyy") & "# ORDER BY Fecha"
Set RStingreso = DbTBE2.OpenRecordset(FILTRO, dbOpenDynaset)

Set lista = ListView1.ListItems.Add(, , "")
lista.SubItems(1) = ""
lista.SubItems(2) = ""
lista.SubItems(3) = ""
lista.SubItems(4) = ""
lista.SubItems(5) = ""
lista.SubItems(6) = ""
lista.SubItems(7) = ""
lista.SubItems(8) = ""
lista.SubItems(9) = ""
lista.SubItems(10) = ""
lista.SubItems(11) = ""
lista.SubItems(12) = ""
lista.SubItems(13) = ""
lista.SubItems(14) = ""
lista.SubItems(15) = ""
lista.SubItems(16) = ""
lista.SubItems(17) = ""
lista.SubItems(18) = ""
lista.SubItems(19) = ""
lista.SubItems(20) = ""
lista.SubItems(21) = ""
lista.SubItems(22) = ""
lista.SubItems(23) = ""
lista.SubItems(24) = ""
lista.SubItems(25) = ""
lista.SubItems(26) = ""
lista.SubItems(27) = ""
lista.SubItems(28) = ""
lista.SubItems(29) = ""

Set lista = ListView1.ListItems.Add(, , "")
lista.SubItems(1) = ""
lista.SubItems(2) = ""
lista.SubItems(3) = ""
lista.SubItems(4) = ""
lista.SubItems(5) = ""
lista.SubItems(6) = ""
lista.SubItems(7) = ""
lista.SubItems(8) = ""
lista.SubItems(9) = ""
lista.SubItems(10) = ""
lista.SubItems(11) = ""
lista.SubItems(12) = ""
lista.SubItems(13) = ""
lista.SubItems(14) = ""
lista.SubItems(15) = ""
lista.SubItems(16) = ""
lista.SubItems(17) = ""
lista.SubItems(18) = ""
lista.SubItems(19) = ""
lista.SubItems(20) = ""
lista.SubItems(21) = ""
lista.SubItems(22) = ""
lista.SubItems(23) = ""
lista.SubItems(24) = ""
lista.SubItems(25) = ""
lista.SubItems(26) = ""
lista.SubItems(27) = ""
lista.SubItems(28) = ""
lista.SubItems(29) = ""

End Sub

Private Sub Command8_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Text16.Text = ""
Text17.Text = ""
Text18.Text = ""
Text19.Text = ""
Text20.Text = ""
Text21.Text = ""
Text22.Text = ""
Text23.Text = ""
Text24.Text = ""
Text25.Text = ""
Text26.Text = ""
Text27.Text = ""
Text28.Text = ""
Text29.Text = ""
Text30.Text = ""
End Sub

Private Sub Form_Load()

Set DbTBE2 = OpenDatabase(App.Path & "\TBE2.mdb", True, False, ";pwd=" & "TuPassword")
Set reg = DbTBE2.OpenRecordset("ingresos", dbOpenDynaset)

End Sub

Private Sub Text1_Keypress(keyascii As Integer)
If keyascii = 13 Then
reg.FindFirst "codigo='" & Text28.Text & "'"

If reg.NoMatch Then
MsgBox "no existe"
Text2.SetFocus
Else
Text1.Text = reg!fecha
Text2.Text = reg!guia
Text3.Text = reg!proveedor
Text4.Text = reg!cantidad
Text5.Text = reg!devolucion
text6.Text = reg!farmacia
Text7.Text = reg!trapi
Text8.Text = reg!vivanco
Text9.Text = reg!crucero
Text10.Text = reg!cayurruca
Text11.Text = reg!mantilhue
Text12.Text = reg!futahuente
Text13.Text = reg!carimallin
Text14.Text = reg!sector1
Text15.Text = reg!sector2
Text16.Text = reg!sector3
Text17.Text = reg!procedimiento
Text18.Text = reg!clinicasdentales1
Text19.Text = reg!ira
Text20.Text = reg!era
Text21.Text = reg!salamotora
Text22.Text = reg!prestamos
Text23.Text = reg!saldo
Text24.Text = reg!inventario
Text25.Text = reg!clinicasdentales2
Text26.Text = reg!clinicasdentales3
Text27.Text = reg!clinicasdentales4
Text28.Text = reg!codigo
Text29.Text = reg!medicamento

End If
End If
End Sub

haber si lo entiendes

muxas gracias
  #14 (permalink)  
Antiguo 07/08/2008, 13:39
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

Primero: donde es donde te genera el error al hacer la consulta?.
Segundo: Que es lo que dice el Error.
Tercero: Esta parte no la entiendo muy bien
Código:
Set reg = DbTBE2.OpenRecordset("ingresos", dbOpenDynaset)
Cuarto: coloca esta opción en la busqueda deve de funcionar
Código:
Set RStingreso = DbTBE2.OpenRecordset("SELECT * FROM ingresos WHERE Codigo = #" & text30.text & "# ORDER BY Fecha")
  #15 (permalink)  
Antiguo 07/08/2008, 14:55
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

Primero: el error me arroja de la sgte manera:
no se pudo usar 'C:\Documents and settings\administrador\escritorio\copia de TBE2\TBE2.mdb'; el archivo ya esta en uso.

ese es el error

ese es para abrir la tabla me parece mucho y asi se puedan grabar los datos en la tabla de la BD
Set reg = DbTBE2.OpenRecordset("ingresos", dbOpenDynaset)

gracias
  #16 (permalink)  
Antiguo 08/08/2008, 07:24
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 5 meses
Puntos: 6
Respuesta: Sentencia Sql

Bueno entonces el error no esta en la consulta si no en la base de datos
elimina la linea en rojo
Private Sub Form_Load()

Set DbTBE2 = OpenDatabase(App.Path & "\TBE2.mdb", True, False, ";pwd=" & "TuPassword")
Set reg = DbTBE2.OpenRecordset("ingresos", dbOpenDynaset)

End Sub
  #17 (permalink)  
Antiguo 08/08/2008, 10:47
Avatar de yochy20  
Fecha de Ingreso: julio-2008
Mensajes: 32
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: Sentencia Sql

OK

muxas gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:51.