I have a InMemory that gets created, what I then want to do is run INSERT, UPDATE and DELETE queries on the table. The code i have at the moment is below, I create a new InMemory table, add it to the map (which works).
Dim pInMemTable As ITable 'create Temp DP table Set pWSF = New InMemoryWorkspaceFactory Dim PName As esriSystem.IName Set PName = pWSF.Create("fred", "InMemory", Nothing, 0) ' Debug.Print ">>" + PName.NameString + "<<" Set pFWS = PName.Open Dim pFlds As IFieldsEdit Set pFlds = New esriGeoDatabase.Fields pFlds.AddField MakeField("OBJECTID", esriFieldTypeOID) pFlds.AddField MakeField("DP_REF", esriFieldTypeString, 10) pFlds.AddField MakeField("WANTED", esriFieldTypeString, 1) Dim pUID As New UID pUID.Value = "esriGeodatabase.Object" Dim ptable As ITable Set ptable = pFWS.CreateTable("DP_Temp", pFlds, pUID, Nothing, "") ' Debug.Print ptable. Dim pSAT As IStandaloneTable Set pSAT = New StandaloneTable Set pSAT.Table = ptable pSAT.Name = "DP_Temp999" Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pSATC As IStandaloneTableCollection Set pSATC = pMxDoc.FocusMap pSATC.AddStandaloneTable pSAT pMxDoc.UpdateContents Set pInMemTable = pSAT Dim path As String path = "InMemory/DP_Temp999" If pWSF Is Nothing Then MsgBox "pwsf is nothing" Else ' MsgBox "pwsf is something" 'MsgBox pWSF.WorkspaceDescription(False) 'pwsf.Open( Set pWS = pWSF.OpenFromFile(path, 0) ' **********PWS doesnt get set*********** If pWS Is Nothing Then MsgBox "PWS IS NOTHING" Else MsgBox ("Yes!!") End If End If
but the code fails where PWS is getting set as it always returns as Nothing. I have tried various ways of setting the path value e.g. "InMemory/DP_Temp999", "In_Memory/DP_Temp" and trying the "\" as opposed to "/" but it still comes back as nothing. Does anyone have any ideas please? or is there a better way of executing SQL on a table that will allow SELECT, DELETE and INSERTS.
****UPDATE** Right I have been working on this for a few days have have been able to set pWS, by casting by ptable to a idataset object and then setting pWS to the pdataset propertyset properties which works. However I have then tried the following code, to see if SQL can be executed
If pWS Is Nothing Then MsgBox "PWS IS NOTHING" Else 'MsgBox ("Yes!!") Dim pWorkspaceProperties As IWorkspaceProperties Set pWorkspaceProperties = pWS Dim pWSProperty As IWorkspaceProperty Set pWSProperty = pWorkspaceProperties.Property(esriWorkspacePropertyGroup, esriWorkspacePropCanExecuteSQL) If pWSProperty.IsSupported = True Then MsgBox "SQL is supported" Dim sql As String 'sql = "select * from 'DP_TEMP';" sql = "UPDATE dp_temp set dp_temp.[DP_REF] = 'Test';" pWS.ExecuteSQL sql Else MsgBox "SQL is not supported" End If End If
When the code is run, the pWSProperty.IsSupported returns as True, however when the .ExecuteSQL method is run, I get the following error Runtime Error 445 - Object doesn't support this action. So I am a bit confused as to whether SQL can be run or not.