Reputation: 53
hi everyone i have two tables Patients([NumPatient],[NomPatient],[AdressePatient],[GSM],[Ville],[CIN]) and rdvs([num_rdv],[date_heure_rdv],[etat_rdv],[num_pat]). num_pat is a foreign key in rdvs table . i want to make a joint between the two tables in order to displaye the [NomPatient] in table Patients value according to the value of [num_pat] of the table rdvs i've tried to make it like this code shows but it doesn't work :
Private Sub Combonumrdv_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Combonumrdv.SelectedIndexChanged
Connection()
con.Open()
cmd.CommandText = "select NomPatient from Patients INNER JOIN rdvs on Patients.NumPatient = '" & Combonumrdv.SelectedValue & "' = rdvs.num_pat "
Dim res As String = cmd.ExecuteScalar
txtnompat.Text = res
con.Close()
End Sub
i know that the probleme is in my sql request thanks .
Upvotes: 0
Views: 154
Reputation: 1924
I suppose you were trying to get this
select NomPatient
from Patients INNER JOIN rdvs on Patients.NumPatient = rdvs.num_pat
WHERE rdvs.num_pat = '" & Combonumrdv.SelectedValue & "'
in which you are joining the two tables basing on the foreign key and filtering on the content of a combo.
In any case, if the scenario is simply the one you're describing, you don't need to join the two tables but can get the same result using
SELECT NomPatient
FROM Patients
WHERE NumPatient = '" &Combonumrdv.SelectedValue & "'
Upvotes: 3