如何获得开始日期 [英] How to get the start date

查看:77
本文介绍了如何获得开始日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个datagridview

第一个datagridview有一个no和date

第二个datagridview有一个信用日期,金额,没有应用月份,开始日期和结束date



第一个datagridview来自数据库

和第二个datagridview只有信用日期和金额来自数据库。



得到月份的应用我将总金额除以txtamount.text

然后结束日期是根据应用的月份而不是匹配来自datagridview的结果



例如



datagridview1



没有| duedate

1 | 2015年3月18日

2 | 2015年4月20日

3 | 2015年5月18日

4 | 2015年6月18日

5 | 2015年7月20日

6 | 2015年8月18日

7 | 2015年9月18日

8 | 2015年10月19日

9 | 2015年11月23日

10 | 2015年12月18日

11 | 1/18/2016

12 | 2/18/2016

13 | 3/18/2016





datagridview2



no |开始日期|结束日期

1 | | 2015年3月18日

2 | | 2015年4月20日

3 | | 2015年5月18日

4 | | 2015年6月18日

4 | | 2015年6月18日

5 | | 2015年7月20日

6 | | 2015年8月18日

7 | | 2015年9月18日

9 | | 2015年11月23日

10 | | 2015年12月18日

11 | | 1/18/2016



我坚持开始约会

其中7之后9因此开始日期应该是8号来自datagridview1



顺便说一下我只显示了datagridview2第2列到第4列



我有什么尝试过:



i尝试此代码



 < span class =code-keyword> Dim  TotalAmount  As  整数 =  0  
对于 x = 0 DataGridView2.Rows.Count - 1
TotalAmount + = DataGridView2.Rows(x).Cells(< span class =code-digit> 1 )。值
DataGridView2.Rows(x).Cells( 2 )。值= Math .Truncate(TotalAmount / TextBox1.Text)
If DataGr idView2.Rows(x).Cells( 2 )。Value = DataGridView1.Rows(DataGridView2.Rows(x).Cells( 2 )。值 - 1 )。单元格( 0 )。值然后
DataGridView2.Rows(x).Cells( 4 )。Value = DataGridView1.Rows(DataGridView2。行(x)。细胞( 2 )。值 - 1 )。细胞( 1 )。值
结束 如果
下一步





,输出应为



没有|开始日期|结束日期

1 | 2015年3月18日| 2015年3月18日

2 | 2015年4月20日| 2015年4月20日

3 | 2015年5月18日| 2015年5月18日

4 | 2015年6月18日| 2015年6月18日

4 | 2015年6月18日| 2015年6月18日

5 | 2015年7月20日| 2015年7月20日

6 | 8/18/2015 | 2015年8月18日

7 | 9/18/2015 | 2015年9月18日

9 | 2015年10月19日| 2015年11月23日

10 | 12/18/2015 | 2015年12月18日

11 | 2016年1月18日1/18/2016

解决方案

不确定我是否正确理解您的问题,但由于数据来自数据库,我不会尝试搜索相应的来自控件。相反:



- 如果无法在用户界面中更改数据,为什么不使用JOIN获取查询中的相应行

- 如果可以更改数据,那么我将使用数据源来查找填充网格的数据。例如,如果从数据表填充网格,则从那里搜索相应的行。例如,使用 DataTable.Select Method(String)(System.Data) [ ^

i have two datagridview
the first datagridview has a no and date
the second datagridview has a credit date, amount, no of month applied, start date and end date

the first datagridview is from the database
and the second datagridview only the credit date and amount is from the database.

to get the no of month applied i divide total amount to txtamount.text
then the end date is based from no of month applied then ill match the result from the datagridview

for example

datagridview1

no | duedate
1 | 3/18/2015
2 | 4/20/2015
3 | 5/18/2015
4 | 6/18/2015
5 | 7/20/2015
6 | 8/18/2015
7 | 9/18/2015
8 | 10/19/2015
9 | 11/23/2015
10 | 12/18/2015
11 | 1/18/2016
12 | 2/18/2016
13 | 3/18/2016


datagridview2

no | start date | end date
1 | | 3/18/2015
2 | | 4/20/2015
3 | | 5/18/2015
4 | | 6/18/2015
4 | | 6/18/2015
5 | | 7/20/2015
6 | | 8/18/2015
7 | | 9/18/2015
9 | | 11/23/2015
10 | | 12/18/2015
11 | | 1/18/2016

im stuck on getting the start date
where after 7 its 9 so the start date should be the no 8 from datagridview1

btw i only showed column 2 to 4 of datagridview2

What I have tried:

i tried this code

Dim TotalAmount As Integer = 0
        For x = 0 To DataGridView2.Rows.Count - 1
            TotalAmount += DataGridView2.Rows(x).Cells(1).Value
            DataGridView2.Rows(x).Cells(2).Value = Math.Truncate(TotalAmount / TextBox1.Text)
            If DataGridView2.Rows(x).Cells(2).Value = DataGridView1.Rows(DataGridView2.Rows(x).Cells(2).Value - 1).Cells(0).Value Then
                DataGridView2.Rows(x).Cells(4).Value = DataGridView1.Rows(DataGridView2.Rows(x).Cells(2).Value - 1).Cells(1).Value
            End If
        Next



and the output should be

no | start date | end date
1 | 3/18/2015 | 3/18/2015
2 | 4/20/2015 | 4/20/2015
3 | 5/18/2015 | 5/18/2015
4 | 6/18/2015 | 6/18/2015
4 | 6/18/2015 | 6/18/2015
5 | 7/20/2015 | 7/20/2015
6 | 8/18/2015 | 8/18/2015
7 | 9/18/2015 | 9/18/2015
9 | 10/19/2015 | 11/23/2015
10 | 12/18/2015 | 12/18/2015
11 | 1/18/2016 | 1/18/2016

解决方案

Not sure if I understand your question correctly, but since the data is coming from the database, I wouldn't try to search the corresponding from from the controls. Instead:

- If the data cannot be changed in the user interface, why not fetch the corresponding row in the query using a JOIN
- If the data can be changed, then I would use the data source to find the data from which the grid is populated. For example if you populate the grid from a datatable, then search the corresponding row from there. For example using a DataTable.Select Method (String) (System.Data)[^]


这篇关于如何获得开始日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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