Question

Je suis en train de lire à partir de deux tables dans une base MySQL:

Dim sqlcom As MySqlCommand = New MySqlCommand("Select * from  mother, father where IDNO= '" & TextBox14.Text & "' ", sqlcon)

Je reçois cette -Mais erreur:

Column 'IDNO' in where clause is ambiguous

Voici le code complet:

Dim NoAcc As String
        Dim NoAccmod2 As String
        Dim NoPas As String

        Dim sqlcon As New MySqlConnection("Server=localhost; Database=school;Uid=root;Pwd=nitoryolai123$%^;")
        Dim sqlcom As MySqlCommand = New MySqlCommand("Select * from  mother, father where IDNO= '" & TextBox14.Text & "' ", sqlcon)

        sqlcon.Open()


        Dim rdr As MySqlDataReader
        rdr = sqlcom.ExecuteReader


        If rdr.HasRows Then
            rdr.Read()
            NoAcc = rdr("IDNO")
            If (TextBox14.Text = NoAcc) Then TextBox7.Text = rdr("MOTHER")
            If (TextBox14.Text = NoAcc) Then TextBox8.Text = rdr("MOTHER_OCCUPATION")
            If (TextBox14.Text = NoAcc) Then TextBox10.Text = rdr("FATHER")
            If (TextBox14.Text = NoAcc) Then TextBox11.Text = rdr("FATHER_OCCUPATION")
        End If

suggestions -Tout qui pourraient aider à résoudre ce problème? Ou même d'autres techniques sur la réalisation de l'objectif des données de lecture à partir de deux tables utilisant un lecteur de données?

Ceci est un WinForm, pas un formulaire Web

Était-ce utile?

La solution

Essayez ceci sur votre commande:

Dim sqlcom As MySqlCommand = New MySqlCommand("Select * from  mother, father where mother.IDNO= '" & TextBox14.Text & "' AND father.IDNO = '" & TextBox14.Text  & "'", sqlcon)

Autres conseils

Sans voir le schéma de vos tables, je ne peux pas dire avec certitude, mais je suppose que vos colonnes d'identité portent le même nom dans les deux tables. Pour contourner cela, vous allez avoir besoin de se qualifier pleinement celui que vous cherchez, en utilisant mother.IDNO ou father.IDNO (ou mother.IDNO ET father.IDNO).

Si (TextBox14.Text = noacc) Alors TextBox7.Text = rdr ( "mère")

Si (TextBox14.Text = noacc) Alors TextBox8.Text = rdr ( "MOTHER_OCCUPATION")

Si (TextBox14.Text = noacc) = Alors TextBox10.Text rdr ( "père")

Si (TextBox14.Text = noacc) Alors TextBox11.Text = rdr ( "FATHER_OCCUPATION")

On dirait plutôt ne redondant / inefficace pas?

Aussi, vous pouvez essayer d'utiliser un INNER JOIN au lieu de double IDNO "Où" s

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top