/
default.aspx.cs
69 lines (58 loc) · 1.93 KB
/
default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class main : System.Web.UI.Page
{
string connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\baza.accdb";
int c;
int p;
protected void Page_Load(object sender, EventArgs e)
{
count();
}
public void count()
{
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmdread = new OleDbCommand("SELECT count FROM main WHERE id=1", conn);
try
{
conn.Open();
p = (int)cmdread.ExecuteScalar();
conn.Close();
label1.Text = p.ToString();
if (p < 10)
label1.Text = "000" + label1.Text;
else if (p < 100)
label1.Text = "00" + label1.Text;
else if (p < 1000)
label1.Text = "0" + label1.Text;
if ((int)Application["numVisitors"] != 0)
{
c = (int)Application["numVisitors"];
int r = p + c;
OleDbCommand cmd = new OleDbCommand("UPDATE main SET [count]=@count", conn); /*"UPDATE main SET [count]=@count WHERE [id]=1"*/
cmd.Parameters.AddWithValue("count", r);
/*p = (int)cmd.Parameters.AddWithValue("@count", 4).Value;*/
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
label1.Text = r.ToString();
if (r < 10)
label1.Text = "000" + label1.Text;
else if (r < 100)
label1.Text = "00" + label1.Text;
else if (r < 1000)
label1.Text = "0" + label1.Text;
Application["numVisitors"] = 0;
}
}
finally
{
conn.Close();
}
}
}