Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
{
    base.ItemAdded(properties);

   // System.Diagnostics.Debug.Assert(false);
    SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            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;

            sqlConnection.Open();
            command.ExecuteNonQuery();
            sqlConnection.Close();
        });
}

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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 :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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