使用sql在Vb.net中进行EXTRACT查询

时间:2014-01-14 06:42:05

标签: sql vb.net

这是我的代码然后问题是它不会显示gridlist中的信息。我想在我的两个表中进行内部连接,但它不能使用我的代码。这将是另一种选择?非常感谢您的回答。

    Dim sqlQuery As String = "SELECT Persons.pr_id, Persons.pr_fname, Persons.pr_mname, Persons.pr_lname, Persons.pr_address, Users.UserName, Users.phone_num FROM Persons" & _
                             "INNER JOIN Users ON Persons.pr_id = Users.pr_id" & _
                             " WHERE pr_id='" & TextBox1.Text & "'"
    Dim table As New DataTable
    cn.Close()
    cn.Open()
    With cmd
        .CommandText = sqlQuery
        .Connection = cn
    End With
    With cmd
        .CommandText = sqlQueryUser
        .Connection = cn
    End With

    With sqla
        .SelectCommand = cmd
        .Fill(table)
    End With

    If ListView1.SelectedItems.Count > 0 Then
        'Button20.Visible = True
        'Button10.Visible = True
        'RichTextBox2.Enabled = False
        'senbyCombo.Enabled = False
        'group_sendCombo.Enabled = False
        'title.Enabled = False
        'ListView3.Enabled = True


        id = ListView1.SelectedItems(0).Text
        TextBox1.Text = ListView1.SelectedItems(0).SubItems(0).Text
        TextBox2.Text = ListView1.SelectedItems(0).SubItems(1).Text
        TextBox3.Text = ListView1.SelectedItems(0).SubItems(2).Text
        TextBox4.Text = ListView1.SelectedItems(0).SubItems(3).Text
        TextBox5.Text = ListView1.SelectedItems(0).SubItems(4).Text
        TextBox7.Text = ListView1.SelectedItems(0).SubItems(6).Text


    End If
    cn.Close()

1 个答案:

答案 0 :(得分:1)

您的pr_id ambiguous更改了您的查询:

Dim sqlQuery As String = "SELECT Persons.pr_id, Persons.pr_fname, Persons.pr_mname, Persons.pr_lname, Persons.pr_address, Users.UserName, Users.phone_num FROM Persons" & _
                         "INNER JOIN Users ON Persons.pr_id = Users.pr_id" & _
                         " WHERE Persons.pr_id='" & TextBox1.Text & "'"