How to add multiple Recodrs.

3 posts, 1 answers
  1. Majid
    Majid avatar
    9 posts
    Member since:
    Dec 2008

    Posted 05 Jan 2009 Link to this post

    Hello;

     

    public object ExcuteNonQuery(object persistenceObject)  

     

    {

        ObjectId id = null

     

        try  

        {

            scope.Add(persistenceObject);

            id = scope.GetObjectId(persistenceObject);

     

        }

     

     

        catch (Exception e)  

        {

            scope.Transaction.Rollback();

        }

     

     

        return id;  

    }

    public object AddProperty(Property1 obj)                       Method-1

     

    {

        connection.StartTransaction();

     

     

        object id = connection.ExcuteNonQuery(obj);

     

        connection.EndTransaction();

        connection.DisposeScopeObject();

     

     

        return id;

     

    }


     

    public

     

     

    void AddPropertyFeaturesMapping(Property1 property, ArrayList FeaturesList)                Method-2

     

    {

     

     

        try 

     

        {

            connection.StartTransaction();

     

     

            for (int i = 0; i < FeaturesList.Count; i++)

     

            {

     

     

                ArrayList list = (ArrayList)FeaturesList[i];

     

     

     

                for (int j = 0; j < list.Count; i++)

     

                {

     

     

                    PropertyUnitsFeature feature = (PropertyUnitsFeature)list[j];

     

     

     

                    PropertyUnitsFeaturesList obj = new PropertyUnitsFeaturesList();

     

                    obj.PropertyRegistrationNumber = property.PropertyRegistrationNumber;

                    obj.PropertyUnitFeaturesId = feature.PropertyUnitFeaturesId;

     

     

     

                    object id = connection.ExcuteNonQuery(obj);

     

     

                }

            }

            connection.EndTransaction();

            connection.DisposeScopeObject();

        }

     

     

        catch (Exception e)

     

        {

            connection.RollBackTransaction();

            connection.DisposeScopeObject();

        }

    }


     

     

     

     

     

     

     


    First method is adding property object and second one is adding the features of property. There is m:n relation ship between Property and Features. Problem is that when i add property object, it is added successfully, but when adding features against property it raise error,"No active transaction", when loop is iterating for 2nd time to run "connection.ExcuteNonQuery(obj); " error raises.

     

     

  2. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 06 Jan 2009 Link to this post

    Hello Majid,
    I looked at your code and noticed that in the second cycle " for (int j = 0; j < list.Count; i++)" you increase the "i" counter instead of the "j" one. This probably causes the execution of the ExcuteNonQuery() method with the same object every time and an exception is thrown when trying to add the object in the scope again. When the exception is caught by the try-catch block, the transaction is being rolled back and during the next iteration of the cycle there is no active transaction. Hope this helps.

    Kind regards,
    Alexander
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Majid
    Majid avatar
    9 posts
    Member since:
    Dec 2008

    Posted 09 Jan 2009 Link to this post

    Thanks. Yes instead of j++ i have written i++ and it was problem for me. Again Thank u.
Back to Top