to complete my posting above, here is the full code. I implement start editing already but it gives me error "error:Object reference not set to an instance of an object"
Public Function Updateattrib(ByVal layername As String, ByVal coloumn As String, ByVal myval As String) As String
Dim sc As IServerContext = Nothing
Dim rs As String = ""
Dim r As String
Try
Dim idt As ESRI.ArcGIS.ADF.Identity = New ESRI.ArcGIS.ADF.Identity("myusername", "pwd", "svr-955")
Dim agc As ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection
agc = New ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("svr-955", idt)
agc.Connect()
If (Not agc.IsConnected) Then
MsgBox("not connected")
End If
Dim sm As IServerObjectManager = agc.ServerObjectManager
sc = sm.CreateServerContext("amapservicename", "MapServer")
Dim so As IServerObject = sc.ServerObject
Dim prop As IPropertySet = sc.CreateObject("esriSystem.PropertySet")
'db conn
prop.SetProperty("SERVER", "svr-955")
prop.SetProperty("INSTANCE", "esri_sde")
prop.SetProperty("DATABASE", "reg_opt")
prop.SetProperty("USER", "sde")
prop.SetProperty("PASSWORD", "sde")
prop.SetProperty("VERSION", "sde.DEFAULT")
'prop.SetProperty("VERSION", "SDE.test")
Dim wsf As IWorkspaceFactory = sc.CreateObject("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim fws As IFeatureWorkspace = wsf.Open(prop, 0)
Dim fc As IFeatureClass = fws.OpenFeatureClass(namalayer)
Dim ft As IFeature
Dim tbl As ITable = Nothing
Dim workspc As IWorkspace = Nothing
' Cast the workspace to the IMultiuserWorkspaceEdit and IWorkspaceEdit2 interfaces.
Dim muWorkspaceEdit As IMultiuserWorkspaceEdit = CType(workspc, IMultiuserWorkspaceEdit)
Dim workspaceEdit As IWorkspaceEdit = CType(workspc, IWorkspaceEdit2)
' Start a versioned edit session.
muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned) 'error here
' Start an edit operation.
workspaceEdit.StartEditOperation()
If Not fc Is Nothing Then
Dim i As Integer = fc.FindField(kolom)
If i > -1 Then
Dim qf As IQueryFilter = sc.CreateObject("esriGeoDatabase.QueryFilter")
qf.WhereClause = "field1 = " & "'" & myval & "'" 'field1 is the name of the field in amapservicename
qf.SubFields = coloumnname 'qf.subfields = "*"
qf.AddField("field1")
qf.AddField("field2")
qf.AddField("field3")
Dim fr As IFeatureCursor = fc.Search(qf, False)
'Dim fr As IFeatureCursor = fc.Update(qf,False)
Dim indexfieldtarget As Integer
indexfieldtarget = fc.Fields.FindField("field1") 'target field index
'Debug.Print("targetindex :" & indexfieldtarget)
'print the result
Do
ft = fr.NextFeature()
If Not (ft Is Nothing) Then
'update the value
ft.Value(indexfieldtarget) = "mydata"
'fr.UpdateFeature(ft)
ft.Store()
End If
Loop Until (ft Is Nothing)
If Len(rs) > 1 Then
rs = Right(rs, Len(rs) - 1)
End If
Else
rs = "error:field not found"
End If
Else
rs = "error:data not found"
End If
' Save the edit operation. To cancel an edit operation, the AbortEditOperation
' method can be used.
workspaceEdit.StopEditOperation()
workspaceEdit.StopEditing(True)
sc.ReleaseContext()
Catch ex As Exception
rs = "error:" & ex.Message
End Try
Return rs
End Function