ASP.net中网站访问量统计方法代码(3)

//存储过程名sp_InsertCountPeopleDay
SqlConnection con1 = Db.DB.createconnection();
con1.Open();
SqlCommand cmd1 = new SqlCommand("sp_InsertCountPeopleDay", con1);
cmd1.CommandType = CommandType.StoredProcedure; //存储过程名

//调用并设置存储过程参数
cmd1.Parameters.Add(new SqlParameter("@peopleDay", SqlDbType.Int));
cmd1.Parameters.Add(new SqlParameter("@dateTimes", SqlDbType.DateTime));

//给参数赋值
cmd1.Parameters["@peopleDay"].Value = countToday;
cmd1.Parameters["@dateTimes"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

cmd1.ExecuteNonQuery();
con1.Close();

//在一个月的最后一天写入本月的访问量
//取本月最后一天(30或者31日)
DateTime lastDay = Convert.ToDateTime(DateTime.Now.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1);
int lastDay1 = DateTime.Now.Day; //取当前时间的日期
if (lastDay1.ToString() == lastDay.ToString()) //如果前日期等于本月最后一天的日期,则前本月的流量写入数据库
{
SqlConnection conM = Db.DB.createconnection();
conM.Open();
SqlCommand cmdM = new SqlCommand("sp_InsertCountPeopleMonth", conM);
cmdM.CommandType = CommandType.StoredProcedure; //存储过程名

//调用并设置存储过程参数
cmdM.Parameters.Add(new SqlParameter("@peopleMonth", SqlDbType.Int));
cmdM.Parameters.Add(new SqlParameter("@dateTimeMonth", SqlDbType.DateTime));

//给参数赋值
cmdM.Parameters["@peopleMonth"].Value = countMonth;
cmdM.Parameters["@dateTimeMonth"].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

cmdM.ExecuteNonQuery();
conM.Close();
}
}
}
}
catch
{

}
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgwzg.html