I am developing a VB.NET program which has the need to join multiple tables and display them on a DataGridView.
I wrote this query:
SELECT m.idMedicos, m.Nombre, m.Apellido, h.idHistorial, h.CedulaP,
r.*, rm.*,
me.Nombre, me.Tipo, me.Administracion
FROM Medicos m
INNER JOIN Historial h ON m.idMedicos = h.idMedicos
INNER JOIN Recetas r ON r.idHistorial = h.idHistorial
INNER JOIN RecetaMedica rm ON rm.idReceta = r.idReceta
INNER JOIN Medicamentos me ON me.idMedicamento = rm.idMedicamento
WHERE h.CedulaP = $dato
($dato
varies with each query)
When I run my program, it fails with the error: "Syntax error in FROM clause".
I tried to add a comma before each INNER
, but the error persists.
Note: I am using a MS Access database, and I run all the queries with an OleDbDataAdapter.
Dim Consulta As New OleDb.OleDbDataAdapter("Select m.idMedicos, m.Nombre, m.Apellido,
h.idHistorial, h.CedulaP, r.*, rm.*, me.Nombre, me.Tipo, me.Administracion
FROM Medicos m INNER JOIN Historial h ON m.idMedicos = h.idMedicos, INNER JOIN Recetas r ON r.idHistorial = h.idHistorial, INNER JOIN RecetaMedica rm ON rm.idReceta = r.idReceta,
INNER JOIN Medicamentos me ON me.idMedicamento = rm.idMedicamento
WHERE h.CedulaP ='" + dato + "'", conexion)
¿Can you guys give me a hand and see what happens here ? :/