Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of plusone3055
plusone3055
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chadmanvb
chadmanvb

ASKER

I still could not get this to work.  Could you show me what to change in my code?
Any ideas?