对于每次迭代,如何写入循环增加从小时到持续时间? [英] How to write for loop increase from hour by Duration for every iteration ?
问题描述
问题
如何根据持续时间从小时开始增加循环次数 每次迭代?
How to write for loop increase from hour by Duration for every iteration ?
我有三个文本框
txt_fromhour 6
txt_tohour   12
txt_Duration 1.5
txt_countduration 4(计算为12-6 = 6 / 1.5 = 4)
我的表名培训有3个字段
I have table name training have 3 fields
serial int
fromhour decimal
tohour  十进制
我需要在三个字段上编写循环插入数据作为下面的示例
I need to write for loop insert data on three fields as sample below
当我从6时开始写到12和12持续时间为1.5,数据将插入如下
when i write fromhour 6 and tohour 12 and duration is 1.5 data will inserted as below
序列   fromhour  tohour
1           6                7.5
2           7.5            9
3           9                10.5
4           10.5          12
for(int i = 0; i< = 4; i ++)
{
插入训练(连续,从时间,到时)值(最大+ 1,??,??)
}
如何编写for循环以在两小时内按时间增加插入数据?
How to write for loop to insert data on two fields fromhour and tohour incremented by duration ?
推荐答案
检查示例:
int first_serial = 1;
decimal begin = 6m;
decimal end = 12m;
decimal step = 1.5m;
int serial = first_serial;
for( decimal fromhour = begin, tohour = begin + step; tohour <= end; fromhour = tohour, tohour += step, ++serial )
{
Console.WriteLine(
" {serial} {fromhour} {tohour}");
// TODO:写入数据库
//。 。 。
}
"{serial} {fromhour} {tohour}" ); // TODO: write to database // . . . }
写入控制台。添加插入数据库的代码。
It writes to console. Add the code that inserts to database.
这篇关于对于每次迭代,如何写入循环增加从小时到持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!