Сравните дату из datetimepicker с датой из базы данных
//How can i do to when i select one date < or = (select u_replica from e_industrial.dbo.e1) from this query, if true show date, if > dont show. private void btn_search_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=....;Initial Catalog=Innux;Persist Security Info=True;"); conn.Open(); SqlDataAdapter SDA = new SqlDataAdapter("select dbo.Alteracoes.Data, dbo.Funcionarios.numero as no, dbo.Funcionarios.nome, DATEPART(hour, Falta) AS faltas, DATEPART(hour, Coluna2) AS horasextra from dbo.Alteracoes inner join dbo.Funcionarios on dbo.Alteracoes.IDFuncionario = dbo.Funcionarios.IDFuncionario inner join dbo.Departamentos on dbo.Funcionarios.IDDepartamento = dbo.Departamentos.IDDepartamento WHERE Data = '" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "'", conn); DataSet dt = new DataSet(); SDA.Fill(dt, "dbo.Alteracoes.Data"); dataGridView1.DataSource = dt.Tables["dbo.Alteracoes.Data"]; conn.Close(); } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { //dateTimePicker1.MaxDate = DateTime.Now; SqlConnection conn = new SqlConnection("Data Source=.....;Initial Catalog=Innux;Persist Security Info=True;"); conn.Open(); SqlDataAdapter pickerMaxDate = new SqlDataAdapter("select u_replica from e_industrial.dbo.e1 ('"+ dateTimePicker1.Value.ToString("yyyy/MM/dd")+"')" , conn); String pickerMaxDateString = pickerMaxDate.ToString(); DateTime dtMax = Convert.ToDateTime(pickerMaxDateString); dateTimePicker1.MaxDate = dtMax; conn.Close(); }
Что я уже пробовал:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { //dateTimePicker1.MaxDate = DateTime.Now; SqlConnection conn = new SqlConnection("Data Source=.....;Initial Catalog=Innux;Persist Security Info=True;"); conn.Open(); SqlDataAdapter pickerMaxDate = new SqlDataAdapter("select u_replica from e_industrial.dbo.e1 ('"+ dateTimePicker1.Value.ToString("yyyy/MM/dd")+"')" , conn); String pickerMaxDateString = pickerMaxDate.ToString(); DateTime dtMax = Convert.ToDateTime(pickerMaxDateString); dateTimePicker1.MaxDate = dtMax; conn.Close(); }
Karthik_Mahalingam
вы получаете какую-нибудь ошибку?