csharp79

Update query to shapefile

Discussion created by csharp79 on Sep 21, 2011
Latest reply on Sep 21, 2011 by agray1
Hi forum,
I would like to update the attribute table of a shapefile but the code that I wrote doesn't works,
can you help me please?
public static void UpdateFoglioParticelle(int fid, string newFoglio, string newParticella, string shapeName, string path)
        {

            String shapefileStringTemplate = "Provider=ESRI.GeoDB.OleDB.1;Data Source={0};"
                + "Extended Properties=workspacetype=esriDataSourcesFile.ShapefileWorkspaceFactory.1;Geometry={1}";
            String connectionString = String.Format(shapefileStringTemplate, path, shapeName);

            //string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + shapeName;
            OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
            OleDbCommand command = myOleDbConnection.CreateCommand();

            //OleDbCommand command = new OleDbCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = String.Format(@"UPDATE {0} SET FOGLIO = {1}, PARTICELLA = {2} WHERE FID = {3}", shapeName, newFoglio, newParticella, fid);
            //command.Connection = OleDbObjects.Instance.GetConnection();

            try
            {
                myOleDbConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errore nella query di update:\n" + ex);
            }
            finally
            {
                if (myOleDbConnection.State != ConnectionState.Closed)
                    myOleDbConnection.Close();
            }
        }


Where is the error?

Please help me...
Thanks in advance!!!

Outcomes