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"
        Dim cmd As New OleDbCommand
        Dim dr As OleDbDataReader
        cmd = New OleDbCommand("select Title from Titles", con)
        dr = cmd.ExecuteReader
        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)
        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")
            MsgBox("An XML Does NOT Exist For This Title Or There Is A Title Mismatch")
        End If
    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.