求大虾帮忙修改下代码,急急急~~~~~
[img=http://localhost:49380/%E7%A8%8B%E5%BA%8F/Default.aspx][/img]using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class IpStat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
statIp();
}
protected void statIp()
{
//判断查看的是日还是月的回访率
if (Request["id"] == "day")
{
//设置查询日的条件
string sqlSumNum = "and months=" + DateTime.Now.Month + " and days=" + DateTime.Now.Day;
string sqlCount = " months= " + DateTime.Now.Month + " and days=" + DateTime.Now.Day;
Label1.Text = DateTime.Now.Year + "年" + DateTime.Now.Month + "月"+DateTime.Now.Day+"日";
//调用自定义方法,用来创建表格并以百分比显示日回访率
createTable(sqlSumNum, sqlCount);
}
else if(Request ["id"] == "month")
{
//设置查询月的条件
string sqlSumNum = "and months=" + DateTime.Now.Month;
string sqlCount = " months= " + DateTime.Now.Month;
Label1.Text = DateTime.Now.Year+"年"+DateTime.Now.Month+"月";
//调用自定义方法,用来创建表格并以百分比显示月回访率
createTable(sqlSumNum, sqlCount);
}
else if (Session["id"].ToString() == "button")
{
string month = Session["month"].ToString();
string day = Session["day"].ToString();
string sqlSumNum = "and months=" + month + " and days=" + day ;
string sqlCount = " months= " + month + " and days=" + day ;
Label1.Text = DateTime.Now.Year + "年" + month + "月" + day + "日";
//调用自定义方法,用来创建表格并以百分比显示日回访率
createTable(sqlSumNum, sqlCount);
}
}
/// <summary>
/// 以表格的形式显示日或月的回访率
/// </summary>
/// <param name="sqlSumNum">字符串变量,表示查询指定访问人数的条件</param>
/// <param name="sqlCount">字符串变量,表示查询总访问人数的条件</param>
protected void createTable(string sqlSumNum, string sqlCount)
{
//设置字符串,使用html代码创建表格,该表格为三列分别显示,回访率,访问人数,总人数比例
string str = "<body style=text-align:center><table border=1 width='600' cellpandding=0 cellspacing=0 text-align:center > ";
str = str + "<tr class='zi2'><td align='center' width='200'>回访率</td><td align='center' width='100'>访问人数</td><td width='300'>总人数比例</td></tr>";
//通过for循环,循环添加10行数据
for (int i = 0; i < 10; i++)
{
str = str + "<tr class='zi3'>";
//for循环,循环添加每列数据
for (int j = 0; j < 4; j++)
{
//编写SQL语句,查询日或月的访问总人数
string sqlc = "select count(sumNum) from tb_dayStat where" + sqlCount;
double count = Convert.ToDouble(dataOperate.getTier(sqlc)); //count为当天(月)访问的总人数(不同的ip数)
//判断是否是第10行
if (i <= 8)
{
//编写SQL语句,查询指定访问次数的总人数
string sql = "select count(sumNum) from tb_dayStat where sumNum=" + (i + 1) + sqlSumNum;
double sumNum = Convert.ToDouble(dataOperate.getTier(sql)); //sumNum为当天(月)访问指定次数的人数(例如访问次数为2的人数)
//判断是否是第一列,如果是第一列写回访率次数
if (j == 0)
{
//判断是否是第一行,第一行写第一次访问
str = str + "<td align='center' >第" + number(i) + "次回访</td>";
}
else if (j == 1)
{
str = str + "<td align='center' >" + sumNum + "</td>";
}
else if (j == 2)
{
double result = (sumNum / count) * 100; //总人数比例
str = str + "<td align='left' ><img src=Images/bar1.gif height=10 width= " + result.ToString("#0.00") + " %>  " + result.ToString("#0.00") + "%</td>";
}
}
else
{
//创建SQL语句,查询访问总数大于10的总人数
string sql = "select count(sumNum) from tb_dayStat where sumNum >=" + (i+1) + sqlSumNum;
int sumNum = Convert.ToInt32(dataOperate.getTier(sql));
if (j == 0)
{
str = str + "<td align='center' >第十次回访(或多余十次)</td>";
}
else if (j == 1)
{
str = str + "<td align='center' >" + sumNum + "</td>";
}
else if (j == 2)
{
double result=(sumNum/count)*100;
str = str + "<td align='left' ><img src=Images/bar1.gif height=10 width= " + result.ToString("#0.00") + " %>  " + result.ToString("#0.00") + "%</td>";
}
}
}
str = str + "</tr>";
}
str = str + "</table></body>";
//将表格通过Literal控件显示在页面中
Literal1.Text = str;
}
//自定义方法,用来返回大写数字
protected string number(int i)
{
string[] num = { "一", "二", "三", "四", "五", "六", "七", "八", "九" };
return num[i];
}
protected void chaxun_Click(object sender, EventArgs e)
{
Session["id"] = "button";
Session["month"] = this.DropDownList2.SelectedItem.Value;
Session["day"] = this.DropDownList1.SelectedItem.Value;
Response.Redirect("IpStat.aspx");
}
}
--------------------编程问答-------------------- 这么多。。。
到底神马问题!!! --------------------编程问答-------------------- ⊙﹏⊙b汗,图片没粘上去
“/程序”应用程序中的服务器错误。
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 38: createTable(sqlSumNum, sqlCount);
行 39: }
行 40: else if (Session["id"].ToString() == "button")
行 41: {
行 42: string month = Session["month"].ToString();
源文件: d:\Visual Studio 2010\WebSites\程序\IpStat.aspx.cs 行: 40
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
IpStat.statIp() in d:\Visual Studio 2010\WebSites\程序\IpStat.aspx.cs:40
IpStat.Page_Load(Object sender, EventArgs e) in d:\Visual Studio 2010\WebSites\程序\IpStat.aspx.cs:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
--------------------编程问答-------------------- else if (Session["id"].ToString() == "button")
==》》
string id = Session["id"] as string;
else if (id == "button") --------------------编程问答-------------------- Session["id"]不存在的时候,得到是NULL
null是不能.toString()的,
--------------------编程问答-------------------- 能加个好友吗?还有好多问题呢 --------------------编程问答-------------------- string id = Session["id"] as string;
else if (id == "button")
输入进去,else if直接是无效的表达式 --------------------编程问答-------------------- else if ("button".Equals(id)) --------------------编程问答-------------------- 也还是不行。。
补充:.NET技术 , ASP.NET