错误:列'代码'被约束为唯一。值'3'已经存在

时间:2016-03-23 20:17:09

标签: sql .net vb.net

当我更改具有另一个组合框的组合框索引时,我发现此错误

Private Sub cmbcollege_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbcollege.SelectedIndexChanged

    Dim sql As String = "select major ,code from major_code where code in (select major from college_major where college = " & cmbcollege.SelectedValue & ")"
    Dim dt As New SqlDataAdapter(sql, CON)
    Dim ds As New DataSet
    Try
        CON.Open()
        dt.Fill(ds)
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        CON.Close()
    End Try
    Dim c As Integer = ds.Tables(0).Rows.Count - 1
    For i As Integer = 0 To c
        cmbMajor.DisplayMember = "major"
        cmbMajor.ValueMember = "code"
        cmbMajor.DataSource = ds.Tables(0)

    Next
End Sub

0 个答案:

没有答案