setup primary key for a table visual basic .net 2.0

How can I setup a primary key in the "Serial" column  to do searches with this table I have setup.

  Dim CSVdt1 As DataTable
        'read csv file to create data table for search

        CSVdt1 = New DataTable("CSV_Data")

        CSVdt1.Columns.Add("Name")
        CSVdt1.Columns.Add("Serial")
        CSVdt1.Columns.Add("Description")
        CSVdt1.Columns.Add("Software")
        CSVdt1.Columns.Add("InstallDate")
        CSVdt1.Columns.Add("Notes")
        CSVdt1.Columns.Add("Location")
        CSVdt1.Columns.Add("Perm")
        CSVdt1.Columns.Add("PilotPatch")
        CSVdt1.Columns.Add("SwitchInfo")    'switchinfo
        CSVdt1.Columns.Add("CubeNumer")   'newcube desk location
        CSVdt1.Columns.Add("DeskPortNumber")   'desk port number
        CSVdt1.Columns.Add("AvailableRemote")   'na
        CSVdt1.Columns.Add("CabinetLocation")
        CSVdt1.Columns.Add("misc1")
        CSVdt1.Columns.Add("Misc2")
        CSVdt1.Columns.Add("Misc3")
        Dim sr As System.IO.StreamReader
        Dim strContents() As String = Nothing
        Dim strData() As String = Nothing

        Try
            sr = New System.IO.StreamReader(workstationstext)
            strContents = System.Text.RegularExpressions.Regex.Split(sr.ReadToEnd, "\r\n")
            sr.Close()
        Catch Ex As Exception
            Console.WriteLine(Ex.Message)
        End Try
        For Each strLine As String In strContents
            If strLine.StartsWith(";") Or strLine.Length = 0 Then
                'skipping(line)
            Else
                Try

                    strData = strLine.Split(",")
                    CSVdt1.Rows.Add(strData)
                Catch ex As Exception

                    MessageBox.Show("The csv file contains errors!", "Error Found In csv File" & vbCrLf & strLine, MessageBoxButtons.OK, MessageBoxIcon.Error)

                    Exit Sub
                End Try

            End If
        Next
chadmanvbAsked:
Who is Participating?
 
plusone3055Commented:
http://stackoverflow.com/questions/2470681/how-to-definie-a-vb-net-datatable-column-as-primary-key-after-creation

You can set the primary key of a table by:

    Dim table As New DataTable()      table.Columns.Add(New DataColumn("MyColumn"))      Dim primaryKey(1) As DataColumn     primaryKey(1) = table.Columns("MyColumn")     table.PrimaryKey = primaryKey
0
 
chadmanvbAuthor Commented:
I still could not get this to work.  Could you show me what to change in my code?
0
 
chadmanvbAuthor Commented:
Any ideas?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.