techlim1

(VB.NEt) oledb connection to a shapefile in a geodatabase

Discussion created by techlim1 on Mar 10, 2011
Latest reply on Mar 11, 2011 by Hornbydd
I would like to make SQL queries from  a table in a shapefile store in a personal geodatabase. For a simple shapefile i use this VB code:

Public Sub DisplayNamesFromShapefile()

        ' Build the connection string.
        Dim shapefileStringTemplate As String = "Provider=ESRI.GeoDB.OleDB.1;Data Source={0};" & "Extended Properties=workspacetype=esriDataSourcesFile.ShapefileWorkspaceFactory.1;Geometry={1}"
        Dim connectionString As String = String.Format(shapefileStringTemplate, "C:\temp\", "WKB")

        ' Create the connection.
        Dim oleDbConnection As OleDbConnection = New OleDbConnection()
        oleDbConnection.ConnectionString = connectionString

        ' Open the connection and create a reader.
        oleDbConnection.Open()


        ' Create the command.
        Dim sqlQuery As String = "SELECT * FROM Province"
        Dim oleDbCommand As OleDbCommand = New OleDbCommand(sqlQuery, OleDbConnection)


        Dim oleDbDataReader As OleDbDataReader = OleDbCommand.ExecuteReader()

        ' Display the values from the NAME field.
        Do While oleDbDataReader.Read()
            Console.WriteLine(oleDbDataReader("Name").ToString())
            Console.WriteLine(oleDbDataReader("Code").ToString())
            Console.WriteLine(oleDbDataReader("Area").ToString())
            Console.WriteLine(oleDbDataReader("Pop1991").ToString())
        Loop

    End Sub

But if my shapefile is store in a personal geodatabes how to proceed?

thanks,

Outcomes