public void Save()
{
int hit = 0;
using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT TOP 1 * from Hitcount order by id desc", conn);
SqlCommand command = new SqlCommand("insert into Hitcount(Name,Hit)values(@Name,@hit)", conn);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
hit = Convert.ToInt32(rdr["hit"]);
hit = hit + 1;
rdr.Close();
}
command.Parameters.AddWithValue("@Name", "default");
command.Parameters.AddWithValue("@hit", hit);
command.ExecuteNonQuery();
conn.Close();
}
}
protected void button1_Click(object sender, EventArgs e)
{
}
{
int hit = 0;
using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("SELECT TOP 1 * from Hitcount order by id desc", conn);
SqlCommand command = new SqlCommand("insert into Hitcount(Name,Hit)values(@Name,@hit)", conn);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
hit = Convert.ToInt32(rdr["hit"]);
hit = hit + 1;
rdr.Close();
}
command.Parameters.AddWithValue("@Name", "default");
command.Parameters.AddWithValue("@hit", hit);
command.ExecuteNonQuery();
conn.Close();
}
}
protected void button1_Click(object sender, EventArgs e)
{
}
No comments:
Post a Comment