← Foro de Visual Basic

PROBLEMAS CON SENTENCIA SQL

Hilo en el foro de Visual Basic · 01 de Diciembre del 2005 · 1 respuestas
LIZZZ01 de Diciembre del 2005
Pregunta
TENGO LA SIG. SENTENCIA EN LA CUAL QUIERO AGREGAR TODOS LOS DATOS DE UN GRID A UNA BASE DE DATOS:

For i = 1 To Griddatos.Rows - 1
bus = "insert into temp_PROD (CLAVE,DESCRIPCION,TIPO,CAPACIDAD,PRECIOP, PRECIOM, PRECIOR) values ('" & Griddatos.TextMatrix(i, 0) & "', '" & Griddatos.TextMatrix(i, 1) & "','" & Griddatos.TextMatrix(i, 2) & "', '" & Griddatos.TextMatrix(i, 3) & "','" & Griddatos.TextMatrix(i, 4) & "','" & Griddatos.TextMatrix(i, 5) & "','" & Griddatos.TextMatrix(i, 6) & "')"
Fraiche.Execute (bus)
Next i

LO QUE PASA ES QUE HAY CELDAS EN EL GRID DONDE NO HAY NINGUN DATO, ENTONCES LOS REGISTROS DONDE DEBE APARECER EL CAMPO VACIO NO LOS INSERTA.

AYUDA POR FAVOR
URGEEER!!!!

Respuestas 1

mvallejos01 de Diciembre del 2005
Para empezar, intenta armar una cadena sql en la que cada dato, se concatene en una línea diferente, de ese modo, puedes preguntar en un IF, si la celda está vacía o no.

Bus = "insert into temp_PROD (CLAVE,DESCRIPCION,TIPO,CAPACIDAD,PRECIOP, PRECIOM, PRECIOR) values ('"
Bus = Bus & "'" & Griddatos.TextMatrix(i, 0) & "'"
If Griddatos.TextMatrix(i, 1) <> "" then
Bus = Bus & "'" & Griddatos.TextMatrix(i,1) & "'"
else
Bus = Bus & ",Null"
end if

y así la vas completando, dato por dato verificando el contenido de la celda.

Saludos
¿Buscas más hilos como este? Mira el foro de Visual Basic o usa el buscador.