Editing Tables in Feature Service with Silverlight 4

7552
38
01-21-2011 08:34 AM
by Anonymous User
Not applicable
I fielded a question this week that may help other Silverlight 4 developers working with Esri products.  The question was how to add records to a table that lives inside a geodatabase.  While there is probably more then one way to skin this cat, here is one way to do this if you've got the Silverlight Toolkit installed.

In short, I used the Feature Service. If other people have a different implementation feel free to share.





<UserControl x:Class="StandaloneTableEditing.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

   �??- note the SL toolkit package is used here �?� 

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid x:Name="MyForm">
            <Grid.RowDefinitions>
                <RowDefinition Height="40" ></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock Text="Silverlight Standalone Table Editing" Margin="10" FontSize="14" >
            </TextBlock>
            <df:DataForm x:Name="myDataForm" AutoEdit="False" CommandButtonsVisibility="All" Grid.Row="1" Width="400" Height="300" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top" >
            </df:DataForm>
        </Grid>

    </Grid>

</UserControl>





using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using System.ComponentModel;

//Check to aake sure the System.ComponentModel reference has been added

namespace StandaloneTableEditing
{
    public partial class MainPage : UserControl
    {
        public string Owner { get; set; }
        public int Value { get; set; }
        public string Approved { get; set; }
        public int Lastupdate { get; set; }
        public Inspection inspection { get; set; }
        public FeatureLayer featurelayer { get; set; }

        public MainPage()
        {
            InitializeComponent();
            InitializeFeatureService();
            InitializeInspection();
            myDataForm.CurrentItem = inspection;  // Set up data form with data using the set Inspection Class below
        }


        private void InitializeInspection()
        {
            //Set up default values
            inspection = new Inspection()
            {
                Owner = "David Hasselhoff ",
                Value = 100,
                Approved = "Bay Watch",
                Lastupdate = 1111,
                InspectionFeatureLayer = featurelayer
            };
        }

        public void InitializeFeatureService()
        {
            featurelayer = new FeatureLayer();
            featurelayer.Url = "http://serverbox/ArcGIS/rest/services/EditingTables/FeatureServer/1";
            featurelayer.AutoSave = false;
            featurelayer.Mode = FeatureLayer.QueryMode.OnDemand;
            featurelayer.Initialized += Table_IsInitialized;
            featurelayer.Initialize();
            featurelayer.EndSaveEdits += Insert_EndSaveEdits;
            featurelayer.SaveEditsFailed += Insert_SaveEditsFailed;

        }

        public void Table_IsInitialized(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("it's initialized...");
        }

        public void Insert_SaveEditsFailed(object sender, EventArgs e)
        {
            string mes = e.ToString();  // For debugging
            System.Diagnostics.Debug.WriteLine(mes);
        }

        public void Insert_EndSaveEdits(object sender, EventArgs e)
        {
            string mes = e.ToString(); // For debugging
            System.Diagnostics.Debug.WriteLine(mes);
        }

    }

    public class Inspection : IEditableObject
    {
        public string Owner { get; set; }
        public int Value { get; set; }
        public string Approved { get; set; }
        public int Lastupdate { get; set; }
        public Inspection TempInspection { get; set; }
        public FeatureLayer InspectionFeatureLayer;

        public void BeginEdit()
        {
            // Save current Values
            TempInspection = new Inspection()
            {
                Owner = this.Owner,
                Value = this.Value,
                Approved = this.Approved,
                Lastupdate = this.Lastupdate
            };
        }

        public void CancelEdit()
        {
            // Reset Values
            Owner = TempInspection.Owner;
            Value = TempInspection.Value;
            Approved = TempInspection.Approved;
            Lastupdate = TempInspection.Lastupdate;
        }

        public void EndEdit()
        {

            ESRI.ArcGIS.Client.Graphic graphicAttribute = new ESRI.ArcGIS.Client.Graphic();
            graphicAttribute.Attributes.Add("OWNER", this.Owner);
            graphicAttribute.Attributes.Add("VALUE", this.Value);
            graphicAttribute.Attributes.Add("APPROVED", this.Approved);
            graphicAttribute.Attributes.Add("LASTUPDATE", this.Lastupdate);
            InspectionFeatureLayer.Graphics.Add(graphicAttribute);
            InspectionFeatureLayer.SaveEdits();

        }


    }


}





Regards,
Doug Carroll, ESRI Support Services SDK Team
http://support.esri.com/
0 Kudos
38 Replies
JenniferNery
Esri Regular Contributor
After googling around, VB does not support Anonymous methods 😞 that's why the conversion tool did not pick it up.

You can try converting the following code instead:
   l.Initialized += new EventHandler<EventArgs>(l_Initialized);
  }

  void l_Initialized(object sender, EventArgs e)
  {
   var l = sender as FeatureLayer;
   l.Update();
  }


to replace this code:
   l.Initialized += (s, e) => { l.Update(); };
0 Kudos
KenCarrier
Occasional Contributor III
Jennifer the conversion wasn't quite so forward here is what I came up with.

l.IsInitialized += New EventHandler(Of EventArgs)(l_Initialized) 'In VB there is not .Initialized option

'There is also an error being thrown where the underline is
"Error 1 Delegate 'System.EventHandler(Of System.EventArgs)' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor."

The sub routine looks like this

    Private Sub l_Initialized(ByVal sender As Object, ByVal e As EventArgs)
        Dim l = TryCast(sender, FeatureLayer)
        l.Update()
    End Sub

I think we are close just fine tuning the conversions, again I cannot thank you enough for all your help!
0 Kudos
JenniferNery
Esri Regular Contributor
Initialized event is different from IsInitialized. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Layer~Init... vs http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Layer~IsIn.... You subscribe to Initialized event just as you would any event and in the handler, call Update(). IsInitialized boolean property is used to check whether layer had tried to initialized, another property that is usually checked is InitializationFailure which contains exception if there was any. You can look at SDK samples (Code-behind VB) some of them include wiring up to Initialized event: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList. It is similar signature, except you are working with FeatureLayer that has no XAML-code.
0 Kudos
KenCarrier
Occasional Contributor III
Jennifer,

This is proving to be a little too much for me. I cannot seem to convert your code to something useable in VB.

I have put all the various iterations and suggestions below the initializecomponent and nothing seems to be working.

Are you sure what I am attempting is possible because with what I have tried either the application never loads or I get the grid with nothing in it but esri messages.

It seems like you are trying to make me figure this out on my own and I understand that, but I just cannot figure this out and I am frustrated to no end.
0 Kudos
PaulLeedham
New Contributor III
Ken:
I think you may be looking to do something like this (in VB):

Private Sub LoadFeatureLayer()
Dim l as ESRI.ArcGIS.Client.FeatureLayer
l = New ESRI.ArcGIS.Client.FeatureLayer
l.Url = <URL to Feature Service>

AddHandler l.Initialized, AddressOf layerInit
End Sub

Private Sub layerInit(ByVal sender As Object, ByVal args As EventArgs)
      If (sender.GetType Is GetType(FeatureLayer)) Then
         Dim Lay As FeatureLayer = CType(sender, FeatureLayer)
Lay.Update()
End If
End Sub

Thanks,
0 Kudos
KenCarrier
Occasional Contributor III
Jennifer and Paul,

thank you both for your help.

I am stuck on one last detail, I got the query and the FDG wired up but when the results are returned to the FDG the commit button disappears.

I worked with Paul on trying to create my own Commit button and calling l.Update() but that did not work.
XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
 xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid  x:Name="LayoutRoot" Background="White">

        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleMarkerSymbol x:Key="BlackMarkerSymbol" Color="Black" Size="14" Style="Diamond" />
            <esri:PictureMarkerSymbol x:Key="GlobePictureSymbol" OffsetX="8" OffsetY="8" 
                Source="/Assets/images/globe-16x16.png" />
            <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Green" Style="DashDot" Width="4" />
            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="Green" BorderBrush="Blue" 
                BorderThickness="3" />
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="5" />
            <RowDefinition Height="150" />
        </Grid.RowDefinitions>


        <esri:Map x:Name="MyMap" WrapAround="True">

            <esri:FeatureLayer ID="IncidentsLayer"
                               Url="http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
                               DisableClientCaching="True"                                
                               Mode="OnDemand" 
                               AutoSave="True"
                               OnDemandCacheSize="0" 
                               OutFields="*">
            </esri:FeatureLayer>
            <esri:GraphicsLayer ID="MySelectionGraphicsLayer"/>


        </esri:Map>

        <basics:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />

        <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
    Map="{Binding ElementName=MyMap}"
    GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[IncidentsLayer]}"/>

        <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,0" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
            <!--<TextBlock x:Name="ResponseTextBlock" Text="Edit values in the data grid.  When finished, click the Commit button to save to the database." 
                       Width="200" TextAlignment="Left" Margin="30,20,20,30" TextWrapping="Wrap" />-->
        </Grid>
        <Grid HorizontalAlignment="Center" VerticalAlignment="Top"  Margin=" 10,10,10,0">
            <StackPanel Orientation="Horizontal" Margin="5,0,15,0" Canvas.Top="25" >
                <TextBlock Text="US State Name contains:" Margin="10,0,0,0" VerticalAlignment="Center"/>
                <TextBox x:Name="StateNameTextBox" Text="New" Height="23" HorizontalAlignment="Left" VerticalAlignment="Center" Width="125" TextWrapping="NoWrap" 
                     Margin="10,0,10,0" FontSize="12" Background="White" AcceptsReturn="False" />
                <Button Content="Do Query" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="QueryButton_Click" Margin="0,0,10,0" Cursor="Hand" />
                <Button Content="Commit" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="Button_Click" Margin="0,0,10,0" Cursor="Hand" />
            </StackPanel>
        </Grid>


        <Grid HorizontalAlignment="Right"  VerticalAlignment="Top" Margin="10,10,10,0" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />

        </Grid>

    </Grid>

</UserControl>


VB:
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Symbols
Imports ESRI.ArcGIS.Client.Toolkit
Imports ESRI.ArcGIS.Client.Geometry

Partial Public Class MainPage
    Inherits UserControl
    Private Property featurelayer() As FeatureLayer
        Get
            Return m_featurelayer
        End Get
        Set(ByVal value As FeatureLayer)
            m_featurelayer = value
        End Set
    End Property
    Private m_featurelayer As FeatureLayer

    Public Sub New()

        InitializeComponent()

        initializefeatureservice()

    End Sub

    Public Sub initializefeatureservice()

        Dim featurelayer As New FeatureLayer()
        featurelayer.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
        featurelayer.AutoSave = True
        featurelayer.Mode = featurelayer.QueryMode.OnDemand
        featurelayer.Update()
        featurelayer.Initialize()

    End Sub


    Private Sub LoadFeatureLayer()

        Dim l As ESRI.ArcGIS.Client.FeatureLayer
        l = New ESRI.ArcGIS.Client.FeatureLayer
        l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
        Dim s As String
        s = StateNameTextBox.Text
        l.Where = "REL_FACILITYID = '" & s & "'"
        l.OutFields.Add("*")
        l.AutoSave = False

        AddHandler l.Initialized, AddressOf layerInit

        l.Initialize()

    End Sub

    Private Sub layerInit(ByVal sender As Object, ByVal args As EventArgs)
        'Load layer information class.
        If (sender.GetType Is GetType(FeatureLayer)) Then
            Dim Lay As FeatureLayer = CType(sender, FeatureLayer)
            Lay.Update()
        End If
    End Sub

    Private Sub QueryButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim queryTask As New QueryTask("http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1")
        AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
        AddHandler queryTask.Failed, AddressOf QueryTask_Failed

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        'query.Text = StateNameTextBox.Text
        query.ReturnGeometry = False
        Dim s As String
        s = StateNameTextBox.Text

        'MessageBox.Show(s)
        query.Where = "REL_FACILITYID = '" & s & "'"
        ' query.Where = StateNameTextBox.Text
        query.OutFields.Add("*")
        queryTask.ExecuteAsync(query)
    End Sub

    Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
        Dim featureSet As FeatureSet = args.FeatureSet

        featureSet.SpatialReference = MyMap.SpatialReference()



        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then


            MyDataGrid.ItemsSource = featureSet.Features
        Else
            MessageBox.Show("No features returned from query")
        End If

        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MySelectionGraphicsLayer"), GraphicsLayer)

        graphicsLayer.ClearGraphics()

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            For Each feature As Graphic In featureSet.Features
                feature.Symbol = TryCast(LayoutRoot.Resources("RedMarkerSymbol"), SimpleMarkerSymbol)
                graphicsLayer.Graphics.Add(feature)
            Next feature



        End If

        Dim bind As System.Windows.Data.Binding = New System.Windows.Data.Binding()

        bind.ElementName = "MyMap"
        bind.Path = New PropertyPath("Layers.[MySelectionGraphicsLayer]")

        MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, bind)
        MyDataGrid.UpdateLayout()

    End Sub

    Private Sub QueryTask_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs)
        MessageBox.Show("Query execute error: " & args.Error.Message)
    End Sub

    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        m_featurelayer.Update()

    End Sub
End Class


How do I get the commit button to appear once I bind to the FDG? If I can get the commit button to show up I should be good.
0 Kudos
KenCarrier
Occasional Contributor III
One other thing if you click the query button more than once the FDG stops working and nothing is returned.

I have attached 2 screen shots to demonstrate.

When I was trying to wire everything up as Jennifer described I was also seeing the behavior found in SecondQuery.jpg

Thoughts?
0 Kudos
JenniferNery
Esri Regular Contributor
I've tested code from post# 16 and it worked. The difference that I'm seeing with your code is that you declare FeatureLayer in XAML and then again in code-behind. Since the table has no Geometry associated to it, you need not add this to your Map. FeatureDataGrid.GraphicsLayer can be set when you create an instance of FeatureLayer. Try to do one piece at a time, see if you can get FeatureLayer, Initialized and Updated in code-behind. In the event handler, check that you have some graphics. Then try setting FeatureDataGrid to display these graphics.
0 Kudos
KenCarrier
Occasional Contributor III
Jennifer and Paul,

thank you both so much, I finally got this working! If either of you have suggestions for stream lining, cleaning up, or making more efficient I am all ears!!!

XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
 xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid  x:Name="LayoutRoot" Background="White">

        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleMarkerSymbol x:Key="BlackMarkerSymbol" Color="Black" Size="14" Style="Diamond" />
            <esri:PictureMarkerSymbol x:Key="GlobePictureSymbol" OffsetX="8" OffsetY="8" 
                Source="/Assets/images/globe-16x16.png" />
            <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Green" Style="DashDot" Width="4" />
            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="Green" BorderBrush="Blue" 
                BorderThickness="3" />
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="5" />
            <RowDefinition Height="150" />
        </Grid.RowDefinitions>



        <basics:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />

        <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"/>

        <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,0" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
            <!--<TextBlock x:Name="ResponseTextBlock" Text="Edit values in the data grid.  When finished, click the Commit button to save to the database." 
                       Width="200" TextAlignment="Left" Margin="30,20,20,30" TextWrapping="Wrap" />-->
        </Grid>
        <Grid HorizontalAlignment="Center" VerticalAlignment="Top"  Margin=" 10,10,10,0">
            <StackPanel Orientation="Horizontal" Margin="5,0,15,0" Canvas.Top="25" >
                <TextBlock Text="US State Name contains:" Margin="10,0,0,0" VerticalAlignment="Center"/>
                <TextBox x:Name="StateNameTextBox" Text="New" Height="23" HorizontalAlignment="Left" VerticalAlignment="Center" Width="125" TextWrapping="NoWrap" 
                     Margin="10,0,10,0" FontSize="12" Background="White" AcceptsReturn="False" />
                <Button Content="Do Query" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="QueryButton_Click" Margin="0,0,10,0" Cursor="Hand" />
                <!--><Button Content="Commit" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="Button_Click" Margin="0,0,10,0" Cursor="Hand" />-->
            </StackPanel>
        </Grid>


        <Grid HorizontalAlignment="Right"  VerticalAlignment="Top" Margin="10,10,10,0" >
            <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />

        </Grid>

    </Grid>

</UserControl>


VB:
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Symbols
Imports ESRI.ArcGIS.Client.Toolkit
Imports ESRI.ArcGIS.Client.Geometry

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()

        InitializeComponent()

    End Sub

    Private Sub QueryButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim queryTask As New QueryTask("http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1")
        AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
        AddHandler queryTask.Failed, AddressOf QueryTask_Failed

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        'query.Text = StateNameTextBox.Text
        query.ReturnGeometry = False
        Dim s As String
        s = StateNameTextBox.Text

        query.Where = "REL_FACILITYID = '" & s & "'"
        query.OutFields.Add("*")
        queryTask.ExecuteAsync(query)
    End Sub

    Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        Dim l As ESRI.ArcGIS.Client.FeatureLayer
        l = New ESRI.ArcGIS.Client.FeatureLayer
        l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
        Dim s As String
        s = StateNameTextBox.Text
        l.Where = "REL_FACILITYID = '" & s & "'"
        l.OutFields.Add("*")
        l.AutoSave = False

        AddHandler l.Initialized, AddressOf layerInit

        l.Initialize()
        l.ClearGraphics()

        Dim featureSet As FeatureSet = args.FeatureSet

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then

            For Each resultFeature As Graphic In featureSet.Features
                l.Graphics.Add(resultFeature)
            Next

            MyDataGrid.GraphicsLayer = l

        Else
            MessageBox.Show("No features returned from query")
        End If
    End Sub

    Private Sub LoadFeatureLayer()
        Dim l As ESRI.ArcGIS.Client.FeatureLayer
        l = New ESRI.ArcGIS.Client.FeatureLayer
        l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
        l.AutoSave = False
        Dim s As String
        s = StateNameTextBox.Text
        l.Where = "REL_FACILITYID = '" & s & "'"
        l.OutFields.Add("*")

        AddHandler l.Initialized, AddressOf layerInit
        l.Initialize()

    End Sub

    Private Sub layerInit(ByVal sender As Object, ByVal args As EventArgs)
        'Load layer information class.
        If (sender.GetType Is GetType(FeatureLayer)) Then
            Dim Lay As FeatureLayer = CType(sender, FeatureLayer)
            Lay.Update()
        End If
    End Sub

    Private Sub QueryTask_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs)
        MessageBox.Show("Query execute error: " & args.Error.Message)
    End Sub

End Class
0 Kudos
KenCarrier
Occasional Contributor III
Ok so my success was short lived how could I configure this app to add a new record to the same table?
0 Kudos