Problem with inserting SDO_GEOMETRY

Problem with inserting SDO_GEOMETRY

Postby HvG » Mon 04 Feb 2008 15:36

Hi Forum!

We wrote a C# program to insert geometries in our Oracle spatial database.
We would like to insert new Geometries with the "adapter.update" method.
This code looks like this
Code: Select all
public void CreateOracleConnection()
{

            String connectionString = "...";
           
            OracleConnection myConn = new OracleConnection(connectionString);
           
            OracleCommand cmd = new OracleCommand();

            cmd.Connection = myConn;

            cmd.CommandText = "SELECT * FROM geodbland";

            OracleDataAdapter adapter = new OracleDataAdapter(cmd);
           
            DataSet set = new DataSet();

            adapter.Fill(set, "geodbland");

            DataTable t = set.Tables["geodbland"];

            DataRow r = t.NewRow();

            OracleObject sdoObj;
            OracleObject sdoPointObj;
            OracleArray info;
            OracleArray ordinates;

            myConn.Open();

            sdoObj = new OracleObject("MDSYS.SDO_GEOMETRY", myConn);
            sdoPointObj = new OracleObject("MDSYS.SDO_POINT_TYPE", myConn);
            info = new OracleArray("MDSYS.SDO_ELEM_INFO_ARRAY", myConn);
            ordinates = new OracleArray("MDSYS.SDO_ORDINATE_ARRAY", myConn);

            sdoObj["SDO_GTYPE"] = 2001;
            sdoObj["SDO_SRID"] = null;
            sdoObj["SDO_POINT"] = null;
            info.Add("1");
            info.Add("1");
            info.Add("1");
            sdoObj["SDO_ELEM_INFO"] = info;
            ordinates.Add(15);
            ordinates.Add(15);
            sdoObj["SDO_ORDINATES"] = ordinates;

            r["id"] = 14;
            r["name"] = "test2";
            r["geo"] = sdoObj;

            t.Rows.Add(r);

            OracleCommandBuilder builder = new OracleCommandBuilder(adapter);

            ((OracleDataAdapter)adapter).InsertCommand = ((OracleCommandBuilder)(builder)).GetInsertCommand();

             adapter.Update(t);

             /*
             cmd.CommandText = "INSERT INTO geodbland VALUES (20,'test', :OBJ)";
             cmd.Parameters.Add("OBJ", OracleDbType.Object).Value = sdoObj;
             cmd.ExecuteNonQuery();
             */
             
             myConn.Close();
}


We get a NullReferenceException on "adapter.Update(t);"
The commended out part works fine.

What is the problem??

HvG
HvG
 
Posts: 2
Joined: Mon 04 Feb 2008 15:16

Postby Alexey.mdr » Tue 05 Feb 2008 08:48

Please send me a small test project to reproduce the problem.
Also, please include the definition of your own database objects.
Do not use third party components.
Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby HvG » Tue 05 Feb 2008 10:27

Hi Alexey!

Thanks for your answer!
Do not use third party components.

That was the importent note.

Now it works. :)

HvG
HvG
 
Posts: 2
Joined: Mon 04 Feb 2008 15:16

Postby Alexey.mdr » Tue 05 Feb 2008 10:40

Glad to hear that!
Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24


Return to dotConnect for Oracle