日期:2014-05-17 浏览次数:20513 次
protected void btn_cha_Click(object sender, EventArgs e) { if (ddl7.SelectedIndex == 0) { GridView1.DataSource = null; string sql = "select * from [jinhuo] where datediff(day,j_date,'" + DateTime.Now.ToShortDateString() + "')<7 and user_name='" + Session["userName"] + "'"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); GridView1.DataSource = sdr; GridView1.DataBind(); con.Close(); sdr.Close(); } if (ddl7.SelectedIndex == 1) { GridView1.DataSource = null; string sql = "select * from [jinhuo] where datediff(day,j_date,'" + DateTime.Now.ToShortDateString() + "')<15 and user_name='" + Session["userName"] + "'"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); GridView1.DataSource = sdr; GridView1.DataBind(); con.Close(); sdr.Close(); } if (ddl7.SelectedIndex == 2) { GridView1.DataSource = null; string sql = "select * from [jinhuo] where datediff(day,j_date,'" + DateTime.Now.ToShortDateString() + "')<30 and user_name='" + Session["userName"] + "'"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); GridView1.DataSource = sdr; GridView1.DataBind(); con.Close(); sdr.Close(); } if (ddl7.SelectedIndex == 3) { GridView1.DataSource = null; string sql = "select * from [jinhuo] where user_name='" + Session["userName"] + "'"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); GridView1.DataSource = sdr; GridView1.DataBind(); con.Close(); sdr.Close(); } }
private void ExecSql(string sql) { GridView1.DataSource = null; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); GridView1.DataSource = sdr; GridView1.DataBind(); con.Close(); sdr.Close(); } protected void btn_cha_Click(object sender, EventArgs e) { string sql = ""; if (ddl7.SelectedIndex == 0) { sql = "select * from [jinhuo] where datediff(day,j_date,'" + DateTime.Now.ToShortDateString() + "')<7 and user_name='" + Session["userName"] + "'"; } if (ddl7.SelectedIndex == 1) { sql = "select * from [jinhuo] where datediff(day,j_date,'" + DateTime.Now.ToShortDateString() + "')<15 and user_name='" + Session["userName"] + "'"; } if (ddl7.SelectedI