Send Notification to selected users in Asp.Net



Suppose in your website there is an admin control and you want to deliver a message to all or selected users i.e. after login only selected users or every user can see the notification or message from admin of website.
How this task can be achieved?
Follow the following steps. 
1.  Make separate table for message and in login table make another column with bullion type so that whenever it is true user can see the message and we will have to check at the time of login whether this field is true or false. If this is true then user is able to see message stored in database by admin. 


2. On admin side. Make web page like this then admin can search user by name and primary key should be stored separately so that many users can be enabled to see notification. In the image when admin search user by name their primary key will appear to see how many person he want to send notification.
                        


  When admin search name will be automatically added in list.


Create a function and it will be called when search button click event is called.
public void select_users()
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            con.Open();
            using (SqlCommand cmd = new SqlCommand("select name from tablet where appmstregno='"+TextBox1.Text+"'",con))
            {
                cmd.ExecuteNonQuery();
               
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Label1.Text = Label1.Text+dr["name"].ToString()+",";
                    // binding various name in label to show.
                }
            }
        }
    }
 

Now after this when send notification button is clicked we will have to separate all name so that we can update bullion type column to true. Ro accomplish this task we will have to take all name in a string type array and by using foreach method we can execute SQL query.

string[] arra = Label1.Text.Split(',');
        foreach (string k in arra)
        {

            using (SqlConnection con = new SqlConnection())
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("update table nameset bool_type_column=1 where name='"+k+"'", con))
                {
                    cmd.ExecuteNonQuery();
                }
                con.Close();

            }
        }


By this way we can achieve our goal. If you want to send notification to all user no need to search just update bull_type_column from false to true.

Comments

Popular posts from this blog

DTS package conversion in SSIS to use in SQL 2012 and SQL 2016

Infinite Scroll in Asp.Net C# using Javascript without Third party Plugin

Add Custom Tags in Web config file in ASP .Net