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(); } } } }