I wanted to know if you could help me solve a problem that I'm having trouble solving. The problem is this:
I have a database with a table of values that I keep:
- date : dateTime
- value : int
- equipment : int (foreign key that comes from the equipment table)
What I want to do is a search in which I want the user to fill in two textboxes that receive a date in each of them and then I want to click a button to search for a gridview with all the values in that table but only those that are in the range of dates chosen by the user in the two textboxes. I'm working with ASP.NET with C # and my database is Mysql
protected void botaoPequisar_Click(object sender, EventArgs e)
{
try
{ var conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["basedados"].ConnectionString);
DateTime data1 = DateTime.ParseExact(txtDataInicio.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture);
DateTime data2 = DateTime.ParseExact(txtDataFim.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture);
MySqlDataAdapter da = new MySqlDataAdapter("SELECT idConduta,valor_Lido,data_Leitura FROM valores_conduta WHERE data_Leitura BETWEEN " + data1.ToString("yyyy-MM-dd") + " AND " + data2.ToString("yyyy-MM-dd") + " AND idConduta=" + ddlHistorico.SelectedValue + "", conn);
da.SelectCommand.CommandType = CommandType.Text;
DataSet ds = new DataSet();//definir o objecto dadaset (ds)
//preencher os dados
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch(Exception ex) {
}
}