请教一下,我从数据库的取值语句如下,是采用datagridview和文本框text结合使用,下面想采用按时间段来查询(如所附截图所框),所查结果并按时间,降序排序,请各位指导一下如何处理,
另外,这些相关语句是否需要分开,若是在同一条语句上写,是否太长了;
private void button1_Click(object sender, EventArgs e)
{
//连接数据库
conn = new SqlConnection("server=IP;database=DB;user=sa;password=passw0rd");
conn.Open();
//查询条件
SqlString = "select EquipmentName,CreateTime,ParamsName,Value from b_HistoricalData where Equipmentname = '" + comboBox1.Text + "'and ParamsName like '%" + textBox1.Text + "%'";
//配置了与下拉列表绑定,按其查询分类显示
//加载数据并显示
try
{
//查询条件和SqlConnection连接
SqlCommand cmd = new SqlCommand(SqlString, conn);
//数据适配器
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
//DataTable存储数据
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
catch
{ }
finally
{
conn.Close();
}