Start by converting yoru three textbox values to numbers:
Decimal.TryParse Method (System) | Microsoft Docs[
^] will do it, and report errors to the user instead of continuing.
Then create and open your DB connection:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
...
}
Inside the open connection, set up a loop:
while
will do, stopping when the
fromHour
is greater than the
toHour
.
Inside the loop, create an an
SQLCommand
object (with a
using
block as above) and pass the two times to the DB as a parameterized query. If necessary, pass the
serial
value each time (though I'd make it an IDENTITY field in the DB, so SQL handles all that) Increment the
fromHour
by the
duration
.
Easy to do - just give it a try manually and you will see what I mean.