none
How do I create a primary key for an imported Excel file RRS feed

  • Question

  •  

    Hi;

     

    How do I create a primary key for a table that I created with a Select statement ?

    My goal is to add the table to a dataset with a dataAdapter, and then do a lookup between tables in a dataset.

     

     

    Dim connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Spreedsheets\MyExcelFl.xls; Extended Properties = Excel 8.0; "

    Dim conn As New OleDbConnection(connStr)

     

    Try

          conn.Open()

          Dim objCmdSelect As String = "SELECT * FROM [Sheet1$]"

          Dim da1 As OleDbDataAdapter = New OleDbDataAdapter(objCmdSelect, conn)

          da1.Fill(ds1, "DataTable")

    Catch ex As Exception

           MsgBox(ex.Message)

    End Try

     

    It is my understanding that you must have a primary key defined in order to relate tables in your dataset.

     

    Thanks for any insights,

     

    GeeMann

    Wednesday, October 8, 2008 11:02 PM

Answers

  • Thanks Anyway.

     

    I found an answer in this Microsoft Help and Support article : http://support.microsoft.com/kb/310373.

     

    I just needed this statement before filling my adapter :

       

         myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey.

     

     

    Geemann

     

     

     

     

    Thursday, October 9, 2008 4:18 PM