This is a migrated thread and some comments may be shown as answers.
How to add multiple Recodrs.
2 Answers 47 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Majid
Top achievements
Rank 2
Majid asked on 05 Jan 2009, 01:53 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 06 Jan 2009, 04:47 PM
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.
0
Majid
Top achievements
Rank 2
answered on 09 Jan 2009, 01:40 PM
Thanks. Yes instead of j++ i have written i++ and it was problem for me. Again Thank u.
Tags
General Discussions
Asked by
Majid
Top achievements
Rank 2
Answers by
Alexander
Telerik team
Majid
Top achievements
Rank 2
Share this question
or