大概意思是这样的,查询某个人当月的数据!有两个DropDownList一个是选择“年份的”另一个是选择“月份的”选择好了然后单击Button在DataGrid中做显示!
源码如下:
string Jgr = String.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
Jgr = Request.QueryString[ "Jgr "].ToString();
if(!IsPostBack)
{
SqlConnection con = DataCon.DataJCon.JCon();
con.Open();
SqlCommand cmd = new SqlCommand( "Year_GetList ",con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sdr = cmd.ExecuteReader();
this.Nf.DataSource = sdr;
this.Nf.DataTextField = "YearName ";
this.Nf.DataValueField = "YearId ";
this.Nf.DataBind();
this.Nf.Items.Insert(0,new ListItem( "—请选年份— ", "-1 "));
sdr.Close();
SqlCommand cmmd = new SqlCommand( "Month_GetList ",con);
cmmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sdz = cmmd.ExecuteReader();
this.Yf.DataSource = sdz;
this.Yf.DataTextField = "MonthName ";
this.Yf.DataValueField = "MonthId ";
this.Yf.DataBind();
this.Yf.Items.Insert(0,new ListItem( "—请选月份— ", "-1 "));
sdz.Close();
con.Close();
}
}
private void YfCx_Click(object sender, System.EventArgs e)
{
string Jgsj = " ' "+Nf.SelectedItem.Text+ "- "+Yf.SelectedItem.Text+ "-01 ' ";
SqlConnection con = DataCon.DataJCon.JCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand( "exec Work_5500 " + Jgr + ", " + Jgsj,con);
DataSet ds = new DataSet();
sda.Fill(ds, "emp ");
this.DataGrid1.DataSource=ds.Tables[ "emp "];
this.DataGrid1.DataKeyField = "WorkId ";
this.DataGrid1.DataBind();
con.Close();
}
现在出现问题的地方是这句
string Jgsj = " ' "+Nf.SelectedItem.Text+ "- "+Yf.SelectedItem.Text+ "-01 ' ";
Nf和Yf获取的是数据库中的Text,也就好比2009-11-01
但是在数据库中每个月不指“-01日”现在查询到的全是-01日的情况,其它的比方-02 -03 -04 ...... -29 -30 -31 都查询不到!应该如何修改请高手帮着看看吧
------解决方案--------------------------------------------------------
string Jgsj = " ' "+Nf.SelectedItem.Text+ "- "+Yf.SelectedItem.Text+ "-01 ' ";
-----------------
Jgsj 这个变量显示的内容是什么呢?