仅选择3天前的行 [英] Select only rows that have 3 days ago

查看:69
本文介绍了仅选择3天前的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个带有DataGridView的表单。

使用SQL我想从表中选择所有内容,在我的情况下是

SELECT * FROM dbo.ripRiparazioni;,并用黄色突出显示日期为三天的行。



这是我的代码,目前:



  string  SQLquery =   SELECT * FROM dbo.ripRiparazioni; 

SqlDataAdapter da = new SqlDataAdapter(SQLquery,connessione);

DataSet ds = new DataSet();

da.Fill(ds);

dataGridView1.DataSource = ds.Tables [ 0 ];





我该怎么办?

解决方案

首先,颜色设置不是很明显:

 myRow.DefaultCellStyle.BackColor = Color.Yellow; 



然后,处理DGV RowPrePaint事件:

< pre lang =c#> private void MyView_RowPrePaint( object sender,DataGridViewRowPrePaintEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv!= null
{
DataGridViewRow myRow = dataGridView1.Rows [e.RowIndex];
DateTime date =(DateTime)myRow.Cells [ InsertDate]。
if (date.Date > = DateTime.Now.AddDays(-3)。日期)
{
myRow.DefaultCellStyle.BackColor = Color.Yellow;
}
}
}


Hi everyone,

I have a form with a DataGridView.
Using SQL I want to select all content from a table, in my case is
"SELECT * FROM dbo.ripRiparazioni;", and highlight with colour yellow only the rows that have a date of three days ago.

This is my code, at the moment:

string SQLquery = "SELECT * FROM dbo.ripRiparazioni";

            SqlDataAdapter da = new SqlDataAdapter(SQLquery, connessione);

            DataSet ds = new DataSet();

            da.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];



How can I do?

解决方案

First, the colour setting isn't in a vastly obvious place:

myRow.DefaultCellStyle.BackColor = Color.Yellow;


Then, handle the DGV RowPrePaint event:

private void MyView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
    {
    DataGridView dgv = sender as DataGridView;
    if (dgv != null)
        {
        DataGridViewRow myRow = dataGridView1.Rows[e.RowIndex];
        DateTime date = (DateTime)myRow.Cells["InsertDate"].Value;
        if (date.Date >= DateTime.Now.AddDays(-3).Date)
            {
            myRow.DefaultCellStyle.BackColor = Color.Yellow;
            }
        }
    }


这篇关于仅选择3天前的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆