ThinkGeo.com    |     Documentation    |     Premium Support

Shapes save/edit problem

Hi all,


i have a problem in editing and saving of shapes. In the response i got before, there was an attached demo file that allows users to draw and then save shapes using MsSqm2008FeatureSource:


gis.thinkgeo.com/Support/Dis...fault.aspx


when you first run the test, all shapes were drawn and saved well, but as i dig deeper into shapes, i encounter error and spent a wholeday scratching my head. Please try if you can recreate my problem:


1. Draw 2 shapes and save (the SQL file now has 2 rows), exit the program


2. Run the program again, press the "Load" button, the 2 shapes you drawn before was shown successfully


3. Draw a new (3rd) shape, then Save. The error "2 failed" appears. When you run again and load, all 3 shapes are there, so it means the two previously drawn shapes were not saved because they already exist in SQL file.


4. Now there 3 shapes on screen, also 3 rows in SQL file, try to add another (4th) shape, but before you save, empty the SQL file so all 4 shapes will be saved without problem. But when you hit "Save", error message "3 failed", eventhough the SQL file is empty. The row in SQL file is 1 (only the newly drawn was saved), and i checked the number of winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count, it was 4.


In other words, when we call featureSource.CommitTransaction(), only the newly drawn shapes were saved although all shapes were present in InternalFeatures of a TrackShapeLayer. What am i missing here?


Ric


 


 


 


 


 



Ric,


Sorry for the delay.
 
The probolem is related with the “Identity increment” in Rect column, one way to fix it is just skip the Rect value when save values to table, try to replace the following code:

        private void btn_SaveToSql(object sender, EventArgs e)
        {
            winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
 
            string connectString = @"Data Source=SQL2008SERVER\TGSQLSERVER;Initial Catalog=InternalDB;User ID=**;Password=**";
            string tableName = "Post6019TestData";
            string featureId = "Rect";
            MsSql2008FeatureSource featureSource = new MsSql2008FeatureSource(connectString, tableName, featureId);
            featureSource.Open();
            featureSource.BeginTransaction();
 
            GeoCollection<Feature> features = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures;
            foreach (Feature feature in features)
            {
    //This is the statement we added.
                feature.ColumnValues.Remove(featureId);
                featureSource.AddFeature(feature);
            }
 
            TransactionResult result = featureSource.CommitTransaction();
            featureSource.Close();
 
            if (result.TotalFailureCount > 0)
            {
                MessageBox.Show(string.Format("{0} failed",result.TotalFailureCount));
            }
        }
 

 
Let me know if any more questions.
 
Thanks.
 
Yale

Yale, 
  
 Yes this solved my problem. Thanks.

Ric, 
  
 Thanks for your letting us know your status. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale