MaxDes 0 Newbie Poster

hello all, I get the error :
dt.PrimaryKey = New DataColumn() {dt.Columns("Title")}
"These Columns are not unique" when I doubleclick a cell in my datagridview... Does anyone know what I have wrong?

Thank you.

Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = s:\testDB.mdb"
        con.Open()
        Dim cmd As New OleDbCommand
        Dim dr As OleDbDataReader
        cmd = New OleDbCommand("select Title from Titles", con)
        dr = cmd.ExecuteReader
        dr.Read()
        Dim dt As New DataTable
        Dim i As Integer
        Dim count As Integer = dr.FieldCount - 1
        'add columns
        For i = 0 To count
            dt.Columns.Add(dr.GetName(i), dr.GetFieldType(i))
        Next                'add rows
        Do While dr.Read()
            Dim r As DataRow = dt.NewRow
            For i = 0 To count
                r(i) = dr.Item(i)
            Next
            dt.Rows.Add(r)
        Loop
        dt.PrimaryKey = New DataColumn() {dt.Columns("Title")}
        If (dt.Rows.Contains(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString)) Then
            MsgBox("An XMl Exists For This Title")
        Else
            MsgBox("An XML Does NOT Exist For This Title Or There Is A Title Mismatch")
        End If
        dr.Close()
        con.Close()
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.