GOOD DAY PROGRAMMERS!! :twisted:

i just want to know How to do this kind of problem

http://www.daniweb.com/forums/attachment.php?attachmentid=23623&stc=1&d=1327489022

i just want to save the date interval
like i will select the Start Date and End Date

ex.
Start Date/Time: 26-Jan-12 / 03:00:00 PM

End Date/Time: 31-Jan-12 / 03:00:00 PM


how do i save the 27,28,29,30 date??? same time...

:idea: HELP please....

BTW here's my code i used to save the date and time...

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim xSQL As New System.Text.StringBuilder
        xSQL.AppendLine("INSERT INTO tblSample")
        xSQL.AppendLine("(DateDeliver,TimeDeliver,NumOfDays,DateReturn,TimeReturn)")
        xSQL.AppendLine("VALUES")
        xSQL.AppendLine("(@DD,@TD,@ND,@DR,@TR)")

        Dim bReturn As Boolean

        Try
            ListView1.Items.Clear()
            Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Settings.AppDB1)
                cn.Open()
                Dim cmd As New OleDbCommand(xSQL.ToString, cn)

                cmd.Parameters.AddWithValue("@DD", DateTimePicker3.Text.Trim)
                cmd.Parameters.AddWithValue("@TD", DateTimePicker4.Text.Trim)
                cmd.Parameters.AddWithValue("@ND", Button2.Text.Trim)
                cmd.Parameters.AddWithValue("@DR", DateTimePicker5.Text.Trim)
                cmd.Parameters.AddWithValue("@TR", DateTimePicker6.Text.Trim)

                Dim n As Integer = cmd.ExecuteNonQuery()
                
                If n <> 0 Then
                    bReturn = True
                    MessageBox.Show("Successfuly Added!")
                Else
                    bReturn = False
                    MessageBox.Show("Fatal Error!")
                End If
                cmd.Dispose()
            End Using
        Catch ex As Exception
            MessageBox.Show("ERRORdate:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        DateList()
    End Sub
Attachments problem.jpg 41.05 KB

hello !
you can do , like this

'first make this sub
   sub MyInsert(ByVal SaleDate As Date) As Integer
        Try
            MyFields = "(SalesDate)"
            MyValues = "(@SalesDate)"
            MyConn.Open()
            Dim Mycmd As New SqlCommand
            Mycmd.Connection = MyConn
            Mycmd.CommandText = "insert into " & MyTableName & " " & MyFields & " Values " & MyValues
            Mycmd.Parameters.Add("SalesDate", SqlDbType.DateTime).Value = SaleDate
            Mycmd.ExecuteNonQuery()
            MyConn.Close()
            'Return 1
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
end sub

'now use this loop to save your dates
dim InsertDate as datetime
insertDate = datetimepickerFromDate.value.date
while InsertDate<= datetimepickerEndDate
MyInsert(insertdate)
insertdate.AddDays(1)
end while

Hope this will helps you , if your prob is solved with it , please mark this thread solved and vote me up :)
Regards
M.Waqas Aslam

hmmm... well thanks for your help... but i don't know how did you do that kind of coding, it didn't work on me... ^_^ i'm sorry, i'm not that good in analyzing of any format or style made by other programmer ^_^

See if this helps.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tsTemp As TimeSpan = DateTimePicker2.Value - DateTimePicker1.Value '// get Date.Time difference.
        Dim iTemp As Integer = 0
        Do Until iTemp = tsTemp.Days '// loop until.Equals the .Days difference.
            iTemp += 1 '// increase.count for next day.
            MsgBox(DateTimePicker1.Value.Date.AddDays(iTemp)) '// get result.
        Loop
    End Sub

Edited 4 Years Ago by codeorder: n/a

See if this helps.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tsTemp As TimeSpan = DateTimePicker2.Value - DateTimePicker1.Value '// get Date.Time difference.
        Dim iTemp As Integer = 0
        Do Until iTemp = tsTemp.Days '// loop until.Equals the .Days difference.
            iTemp += 1 '// increase.count for next day.
            MsgBox(DateTimePicker1.Value.Date.AddDays(iTemp)) '// get result.
        Loop
    End Sub

where do i put that code in thi??

Private Function AddDate()
        Dim xSQL As New System.Text.StringBuilder
        xSQL.AppendLine("INSERT INTO tblSample")
        xSQL.AppendLine("(DateDeliver,TimeDeliver,NumOfDays,DateReturn,TimeReturn)")
        xSQL.AppendLine("VALUES")
        xSQL.AppendLine("(@DD,@TD,@ND,@DR,@TR)")

        Dim bReturn As Boolean

        Try
            ListView1.Items.Clear()
            Using cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Settings.AppDB1)
                cn.Open()
                Dim cmd As New OleDbCommand(xSQL.ToString, cn)

                cmd.Parameters.AddWithValue("@DD", DateTimePicker3.Text.Trim)
                cmd.Parameters.AddWithValue("@TD", DateTimePicker4.Text.Trim)
                cmd.Parameters.AddWithValue("@ND", Button2.Text.Trim)
                cmd.Parameters.AddWithValue("@DR", DateTimePicker5.Text.Trim)
                cmd.Parameters.AddWithValue("@TR", DateTimePicker6.Text.Trim)

                Dim n As Integer = cmd.ExecuteNonQuery()

                If n <> 0 Then
                    bReturn = True
                    MessageBox.Show("Successfuly Added!")
                Else
                    bReturn = False
                    MessageBox.Show("Fatal Error!")
                End If
                cmd.Dispose()
            End Using
            Return True
        Catch ex As Exception
            MessageBox.Show("ERRORdate:" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        End Try
        DateList()
    End Function

i try it but i get the same StartDate:-/

But Thanks any way! ^_^

Personally I have no idea, Not a db.coder; though I would add it right after you first add the DateTimePicker1's.Value(start.date) and before you add the DateTimePicker2's.Value(end.date).
Good luck.

This article has been dead for over six months. Start a new discussion instead.