Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Event Reciever on a Fomr to Update a SQL Database

$
0
0

 I have a database in SQL Server named Title, the table name is also Title and the Field name Title

I am trying to insert into the database a new Title with an event receiver,

Here is the code

namespace ListER_5_2_102.DataList.Lisen
{
    public class Lisen : SPItemEventReceiver
    {
        public override void ItemAdding(SPItemEventProperties properties)
        {
           try
            {
                this.EventFiringEnabled = false;

                AddToDataBase(properties);
            }
            catch (Exception)
            {
                //log here
            }
            finally
            {
                this.EventFiringEnabled = true;
            }

        }
         private void AddToDataBase(SPItemEventProperties properties)
         {
            string connectionString = "Data Source=WIN-CS8A2N41PLU\\SHAREPOINT;Initial Catalog=Title;Integrated Security=True";
            using (SqlConnection con = new SqlConnection(connectionString))
            using (SqlCommand cmd = new SqlCommand("Title", con))
            {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Title", SqlDbType.VarChar).Value = properties.ListItem.Title.ToString();
            //cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = properties.ListItem.Name.ToString();

            con.Open();
            cmd.ExecuteNonQuery();
            }
        }
     }
  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>