I am trying to add few details for a item that is added to a list to SQL database table using a stored procedure, it works perfectly but when I upload multiple files it adds all of the items into the database, whereas My requirement is to just add 1 any of them Item details in the database, not sure if I can do it or not, here is the code.

    public override void ItemAdded(SPItemEventProperties properties)

   // System.Diagnostics.Debug.Assert(false);

            SqlConnection sqlConnection = new SqlConnection(ConnectionString());
            SqlCommand command = new SqlCommand("InsertItemDetails", sqlConnection);
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add("@SiteURL", SqlDbType.VarChar).Value = properties.WebUrl;

            command.Parameters.Add("@ItemName", SqlDbType.VarChar).Value = properties.ListItem.Title;

            command.Parameters.Add("@TimeItemAdded", SqlDbType.DateTime).Value = DateTime.Now;


I think I can add a filter for URL as if it already exists in database then delete that row and add a new Item, but not sure if it will be effective solution.


I created two more stored procedures,

  1. One for checking if any item exists in table
  2. Second to delete all records associated to item details of added item

so first I check if item details are in DB if they are then delete them and add a new item new details.

Hope it helps if someone else came across same problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.