shubham upadhyay

shubham upadhyay

  • NA
  • 31
  • 6.5k

visitor counter at each page

Jan 8 2020 11:53 PM
I want to add views count of each description page of article .when I doing a method ,there is a incremenation of +1 views in all articles.How can we seperate views for each articles by declaring id?
here is my code:
protected void Page_Load(object sender, EventArgs e)
{
findView();
updatecounter();}
}
private void findView()
{
String mycon = (@"Data Source=DESKTOP-KAUS8AP\SQLEXPRESS;Initial Catalog=myblog;Integrated Security=True");
String myquery = "Select * from add_content";
SqlConnection con = new SqlConnection(mycon);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
//Label3.Text = "Website View Counter : " + ds.Tables[0].Rows[0]["viewcount"].ToString();
con.Close();
}
//where (id=@id or id=0)
private void updatecounter()
{
int i = int.Parse(lblview.Text);
lblview.Text = i.ToString();
String mycon = (@"Data Source=DESKTOP-KAUS8AP\SQLEXPRESS;Initial Catalog=myblog;Integrated Security=True");
String updatedata = "update add_content set viewcount=viewcount+1 ";
SqlConnection con = new SqlConnection(mycon);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatedata;
cmd.Connection = con;
cmd.ExecuteNonQuery();
}