SDF unable to Insert, Update.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

SDF unable to Insert, Update.

This post was updated on .
Hello ppl,

 I am trying to write to a SDF file which has the following structure..
SDF File Structure
SDF file name : test_file.sdf
schema name : test1
feature class under the schema - i just have only one : Parcels

which has the property definition : Auto_increment, Name, Area, Perimeter
Name = String - Length(255) - nullable(true) - readonly(false)
Area = String - Length(255) - nullable(true) - readonly(false)
Perimeter = String - Length(255) - nullable(true) - readonly(false)

Copy of the SDF file : test_file.sdf
I am trying various differnt codes to insert some values to the SDF - my app crashes.
here is my code snippet.

//test sdf file
string file = @"D:\Test\SDF_Export\test_file.sdf";

IConnectionManager conmanager = FeatureAccessManager.GetConnectionManager();

using (IConnection con = conmanager.CreateConnection("OSGeo.SDF"))
                //get connection dict
                IConnectionPropertyDictionary conprop = con.ConnectionInfo.ConnectionProperties;
                ed.WriteMessage("\nInside second connection");
                conprop.SetProperty("File", file);
                conprop.SetProperty("ReadOnly", "FALSE");

                OSGeo.FDO.Connections.ConnectionState connstate = con.ConnectionState;

                if (connstate != OSGeo.FDO.Connections.ConnectionState.ConnectionState_Open)
                    ed.WriteMessage("\nCannot read SDF File");

                    ed.WriteMessage("\nSucessfully read SDF!!!! - Ready for insert");
                    //creating iinsert command

                   IInsert insert_cmd = (IInsert)con.CreateCommand(CommandType.CommandType_Insert) as IInsert;

                    //set features class to insert data
                    PropertyValueCollection pcoll = insert_cmd.PropertyValues;
                    //createing values to be inserted
                    PropertyValue pval1 = new PropertyValue();
                    pval1.Name = new Identifier("Name");
                    Expression ex1 = Expression.Parse("'parcelname1'");

                    PropertyValue pval2 = new PropertyValue();
                    pval2.Name = new Identifier("Area");
                    Expression ex2 = Expression.Parse("'area string'");

                     PropertyValue pval3 = new PropertyValue();
                     pval3.Name = new Identifier("Perimeter");
                     Expression ex3 = Expression.Parse("'Perimeter string'");


                     pval1.Value = (ValueExpression)ex1;
                     pval2.Value = (ValueExpression)ex2;
                     pval3.Value = (ValueExpression)ex2;

                     IFeatureReader reader = insert_cmd.Execute();
                        if (reader.ReadNext())
                            Debug.Fail("insert really worked on a read-only volume");
                        Debug.Fail("insert worked on a read-only volume");
please let me know where I went wrong, I am not able to write the file, file is gien full permission for everyone user. and I am able to create SDF file and add feature class.
-Raghulan Gowthaman
Senior civil BIM Consultant