Hello again,
As I promised, I took a closer look in the example you provided here and you are right. This is the only way to be done for the time been. In fact I think it needs to be extended a little bit. What I mean is that if you take a look in your example as shown below
DataTable dataTable = ExcuteSqlUsingOledb("Select * from [AUSTIN~1]", @"C:\PostsData\Austinstreets.shp");
you assume a short name conversion, [AUSTIN~1] in this example, for this to operate anyway.This conversion is one of the issues existed before hand and had to be tackled. So for reasons of completion I think the correct solution has two legs:
- First we need to make a proper conversion to short file name
- Then use your code to get the Datatable form olddb
Module HellperUitls
<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Function GetShortPathName(ByVal longPath As String, _
<MarshalAs(UnmanagedType.LPTStr)> ByVal ShortPath As System.Text.StringBuilder, _
<MarshalAs(Runtime.InteropServices.UnmanagedType.U4)> ByVal bufferSize As Integer) As Integer
End Function
End module
Public Class ourClass
Public Sub ourSub()
Dim shortPath As New StringBuilder(255)
GetShortPathName(sFileName, shortPath, shortPath.Capacity)
Dim file = shortPath.ToString.Substring(shortPath.ToString.LastIndexOf("\") + 1)
Dim atable As DataTable = ExcuteSqlUsingOledb("select min(first_date), max(last_date) from [" & file & "]", sFileName)
end sub
end class
What I can't understand is why the the OleDbCommand accepts an OleDbConnection constructed with long file names while the actual query executed against this olddb connection can't have a fully named shp file. But I guess it does exactly the same conversion that i do internally.
Let me know what do you think as I am not sure which is more dangerous. To make calls to unmanaged code or to assume some arbitary short name conversion?
Kind Regards
Yiannis