####按照月份查当月工作量问题!请大伙来看看不够++分!谢谢了###
按照月份查询问题!请大伙来帮这小弟看看!到底是那里出现问题了源码如下:存储过程:@ManCharacter int, 这个是人名 人名我用编号来代替
@Nian DateTime 这个是要查询的时间
ManTime这个是数据库中的时间字段类型为DateTime
CREATE PROCEDURE Operation_SelectX
@ManCharacter int,
@Nian DateTime
AS
select
ManID,ManCharacter,ManGsName,ManZzlb,ManTime,ManJg
from
operation
where
ManCharacter = @ManCharacter
and
datediff (m,ManTime,@Nian) = 0
order by ManTime desc
GO
程序代码
单击BitSjCx按钮传参到类中部分
Name为人名
Nian为年份
Yue为月份
protected void BitSjCx_Click(object sender, EventArgs e)
{
Xx = ManSelect_Server.SelectX(Convert.ToInt32(Name.SelectedValue), Convert.ToInt32(Nian.SelectedValue), Convert.ToInt32(Yue.SelectedValue));
}
类中代码ManSelect_Server
public static string SelectX(int Xm,int Nian,int Yue)
{
SqlConnection con = WebData.CarCon();
con.Open();
SqlCommand cmd = new SqlCommand("Operation_SelectX", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter Mz = new SqlParameter("@ManCharacter", SqlDbType.Int, 4);
Mz.Value = Xm;
cmd.Parameters.Add(Mz);
SqlParameter Nf = new SqlParameter("@Nian", SqlDbType.DateTime, 8);
Nf.Value = Convert.ToDateTime(DateTime.Today.AddYears(Nian).AddMonths(Yue).AddDays(01));
cmd.Parameters.Add(Nf);
System.Text.StringBuilder Xx = new System.Text.StringBuilder();
SqlDataReader sdr = cmd.ExecuteReader();
Xx.Append("<div class=\"Carlb bk1\">");
Xx.Append("<div class=\"idd jz bk3\">编号</div>");
Xx.Append("<div class=\"pp jz bk3\">制作人</div>");
Xx.Append("<div class=\"xl jz bk3\">公司名称</div>");
Xx.Append("<div class=\"xh jz bk3\">制作类别</div>");
Xx.Append("<div class=\"sj jz bk3\">工作单时间</div>");
Xx.Append("<div class=\"xj jz bk3\">工作单状况</div>");
Xx.Append("<div class=\"xx jz\">相关操作</div>");
Xx.Append("</div>");
while (sdr.Read())
{
string Name = string.Empty;
if (sdr["ManCharacter"].ToString() == "1")
{
Name = "小王";
}
else if (sdr["ManCharacter"].ToString() == "2")
{
Name = "小张";
}
else if (sdr["ManCharacter"].ToString() == "3")
{
Name = "小于";
}
else if (sdr["ManCharacter"].ToString() == "4")
{
Name = "小隋";
}
else if (sdr["ManCharacter"].ToString() == "5")
{
Name = "小赵";
}
else if (sdr["ManCharacter"].ToString() == "6")
{
Name = "小李";
}
string Zzlb = string.Empty;
if (sdr["ManZzlb"].ToString() == "1")
{
Zzlb = "制作网页";
}
else if (sdr["ManZzlb"].ToString() == "2")
{
Zzlb = "修改网页";
}
else if (sdr["ManZzlb"].ToString() == "3")
{
Zzlb = "制作动画";
}
else if (sdr["ManZzlb"].ToString() == "4")
{
Zzlb = "修改动画";
}
else if (sdr["ManZzlb"].ToString() == "5")
{
Zzlb = "新闻发布";
}
else if (sdr["ManZzlb"].ToString() == "6")
{
Zzlb = "经典车型";
}
string Sfwc = string.Empty;
if (Convert.ToBoolean(sdr["ManJg"]) == true)
{
Sfwc = "已完成";
}
else if (Convert.ToBoolean(sdr["ManJg"]) == false)
{
Sfwc = "未完成";
}
Xx.Append("<div class=\"Carlb bk2\" onmouseout=this.style.backgroundColor='' onmouseover=this.style.backgroundColor='#BFDFFF'>");
Xx.Append("<div class=\"idd jz bk3\">" + sdr["ManID"].ToString() + "</div>");
Xx.Append("<div class=\"pp jz bk3\">" + Name.ToString() + "</div>");
Xx.Append("<div class=\"xl jz bk3\">" + sdr["ManGsName"].ToString() + "</div>");
Xx.Append("<div class=\"xh jz bk3\">" + Zzlb.ToString() + "</div>");
Xx.Append("<div class=\"sj jz bk3\">" + sdr["ManTime"].ToString() + "</div>");
Xx.Append("<div class=\"xj jz bk3\">" + Sfwc.ToString() + "</div>");
Xx.Append("<div class=\"xx jz\">编辑 <a href=../Operation/ManDelete.aspx?ManID=" + sdr["ManID"].ToString() + "&Qname=" + sdr["ManCharacter"].ToString() + "&Mjg=" + Convert.ToInt32(sdr["ManJg"]) + "&pCurrent=" + 1 + " &onclick ='return dele()'>删除</a></div>");
Xx.Append("</div>");
}
sdr.Close();
sdr.Dispose();
cmd.Dispose();
con.Close();
con.Dispose();
return Xx.ToString();
}
现在的问题是我查询不到数据!数据库中肯定有数据的!请大伙帮这看看到底是程序的问题还是存储过程的问题! --------------------编程问答-------------------- up! --------------------编程问答-------------------- 那你在查询分析器里执行存储过程看能不能查出数据 --------------------编程问答-------------------- EXEC Operation_SelectX 6,'2007-10-31'
在查询分析器中执行存储过程没问题的! --------------------编程问答-------------------- Nf.Value = Convert.ToDateTime(DateTime.Today.AddYears(Nian).AddMonths(Yue).AddDays(01));
这段话起的作用是什么?
你在当前时间的基础上增加了年、月、日,又怎么能查询到过去的数据呢?
补充:.NET技术 , ASP.NET