protected void btn_comment_Click(object sender, EventArgs e) { try { //if (!CheckUserPermissions()) // DateTime dtt = DateTime.Now; dtt.Date.ToString("MM/dd/yyyy"); cn.ConnectionString = ConfigurationManager.ConnectionStrings["legup"].ConnectionString; string queue = "SendQueue"; SqlDependency.Stop(str_con); if(SqlDependency.Start(str_con)) { SqlCommand cmd1 = new SqlCommand(); cmd1.Connection = cn; // cmd1.CommandType = CommandType.StoredProcedure; cmd1.CommandText = "Insert into [legup].[dbo].[legup_comments](project_id,user_id,comments,date) Values (3,1,'" + txt_comments.Text + "','" + dtt + "')"; ////cmd1.CommandText = "sp_insert_comments"; cmd1.Notification = null; //cmd1.Parameters.AddWithValue("@proj_id", 3); //cmd1.Parameters.AddWithValue("@user_id", 1); //cmd1.Parameters.AddWithValue("@comments", txt_comments.Text); //cmd1.Parameters.AddWithValue("@dt", dtt); SqlDependency dependency = new SqlDependency(cmd1); dependency.OnChange += new OnChangeEventHandler(OnDataInsert); cn.Open(); cmd1.ExecuteNonQuery(); txt_comments.Text = String.Empty; display(); } else { Response.Write("failed to start"); } } catch (Exception ex) { Response.Write("<br>DFGH:: " + ex.Message); } finally { // SqlDependency.Stop(str_con); if (cn != null) cn.Close(); } } void OnDataInsert(object sender, SqlNotificationEventArgs e) { SqlDependency dependency = sender as SqlDependency; Response.Write("sucess on data insert"); // Notices are only a one shot deal // so remove the existing one so a new // one can be added dependency.OnChange -= new OnChangeEventHandler(OnDataInsert); // Fire the event Response.Write("<br> Fire the event"); // if (OnNewMessage != null) // { // OnNewMessage(); // } }
int indicate = cmd1.ExecuteNonQuery(); if (indicate==0) { // fail Messagebox.Show("Record Insertion failed") } else { // success Messagebox.Show("Record Inserted Successfully") }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)