Results 1 to 14 of 14

Thread: [2005] Comparing Dates

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    [2005] Comparing Dates

    i think there's something wrong with my code..
    Code:
           txtPayee.Visible = False
            txtAmount.Visible = False
            dtpDate.Visible = False
            objDataAdapter.SelectCommand = New SqlCommand()
            objDataAdapter.SelectCommand.Connection = objConnection
            objDataAdapter.SelectCommand.CommandText = _
            "SELECT MGL_Payee, MGL_TotalAmount, MGL_ReferenceDate FROM tbl_MGLTransaction"
            objDataAdapter.SelectCommand.CommandType = CommandType.Text
    
            Dim objDataSet As New DataSet()
            objConnection.Open()
            objDataAdapter.Fill(objDataSet, "tbl_MGLTransaction")
            objDataView = New DataView(objDataSet.Tables("tbl_MGLTransaction"))
    
            'Clear then Bind
            txtPayee.DataBindings.Clear()
            txtAmount.DataBindings.Clear()
            dtpDate.DataBindings.Clear()
    
            txtPayee.DataBindings.Add("Text", objDataView, "MGL_Payee")
            txtAmount.DataBindings.Add("Text", objDataView, "MGL_TotalAmount")
            dtpDate.DataBindings.Add("Value", objDataView, "MGL_ReferenceDate")
            objConnection.Close()
    
            Dim tempDate As DateTime = dtpDate.Value
            Dim dateThirty As Date = tempDate.AddDays(30)
            Dim dateSixty As Date = tempDate.AddDays(60)
            Dim dateNinety As Date = tempDate.AddDays(90)
    
            Dim oneToThirtyAmount As New Integer
            Dim thirtyToSixtyAmount As New Integer
            Dim sixtyToNinetyAmount As New Integer
            Dim moreThanNinetyAmount As New Integer
    
            If Now >= tempDate And Now <= dateThirty Then
    
                oneToThirtyAmount = txtAmount.Text
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateThirty And Now <= dateSixty Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = txtAmount.Text
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateSixty And Now <= dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = txtAmount.Text
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = txtAmount.Text
    
            End If
    
            'Bind
            'Insert To Table
            'Retrieve To Table
            'Bind To DataGrid
            'Delete Record From Table
    
            Dim objConnection2 As SqlConnection = New _
            SqlConnection("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            Dim objCommand2 As SqlCommand = New SqlCommand()
            objCommand2.Connection = objConnection2
            objCommand2.CommandText = "INSERT INTO tbl_ARAging " & _
            "(Payee, TotalAmount, ReferDate, OneToThirty, ThirtyToSixty, SixtyToNinety, MoreThanNinety) " & _
            "VALUES(@Payee, @TotalAmount, @ReferDate, @OneToThirty, @ThirtyToSixty, @SixtyToNinety, @MoreThanNinety)"
            objCommand2.Parameters.AddWithValue("@Payee", txtPayee.Text)
            objCommand2.Parameters.AddWithValue("@TotalAmount", txtAmount.Text)
            objCommand2.Parameters.AddWithValue("@ReferDate", dtpDate.Value)
            objCommand2.Parameters.AddWithValue("@OneToThirty", oneToThirtyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@ThirtyToSixty", thirtyToSixtyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@SixtyToNinety", sixtyToNinetyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@MoreThanNinety", moreThanNinetyAmount.ToString)
            objConnection2.Open()
            objCommand2.ExecuteNonQuery()
            objConnection2.Close()
    
            Dim objConnection3 As New SqlConnection _
          ("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            objDataAdapter3.SelectCommand = New SqlCommand()
            objDataAdapter3.SelectCommand.Connection = objConnection3
            objDataAdapter3.SelectCommand.CommandText = ("select Payee, TotalAmount, ReferDate, OneToThirty, ThirtyToSixty, SixtyToNinety, MoreThanNinety FROM tbl_ARAging")
    
            objDataAdapter3.SelectCommand.CommandType = CommandType.Text
    
            Dim objDataSet3 As New DataSet()
            objConnection3.Open()
            objDataAdapter3.Fill(objDataSet3, "tbl_ARAging")
            objDataView3 = New DataView(objDataSet3.Tables("tbl_ARAging"))
    
            grdAuthorTitles.DataSource = objDataSet3
            grdAuthorTitles.DataMember = "tbl_ARAging"
    
            grdAuthorTitles.Columns(0).HeaderText = "Payee"
            grdAuthorTitles.Columns(1).HeaderText = "TotalAmount"
            grdAuthorTitles.Columns(2).HeaderText = "Reference Date"
            grdAuthorTitles.Columns(3).HeaderText = "1 - 30"
            grdAuthorTitles.Columns(4).HeaderText = "31 - 60"
            grdAuthorTitles.Columns(5).HeaderText = "61 - 90"
            grdAuthorTitles.Columns(6).HeaderText = ">90"
    
            objConnection3.Close()
            Dim objConnection4 As New SqlConnection _
          ("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            Dim objCommand4 As SqlCommand = New SqlCommand()
            objCommand4.Connection = objConnection4
            objCommand4.CommandText = ("DELETE FROM tbl_ARAging")
    
            objConnection4.Open()
            objCommand4.ExecuteNonQuery()
            objConnection4.Close()
    1st question:
    the value i always get in oneToThirtyAmount , oneToThirtyAmount , sixtyToNinetyAmount , moreThanNinetyAmount is always 0..
    editted: solved this one too.. tnx to sir .paul. .. below is the solution..

    2nd question:
    why is it? is there a way not to affect the value with setting its visible property to false? i dont want those 3 boxes to appear.. ive done that because i dont know how to bind a data, retrieve from a table, to a variable only without binding it to a textbox/dtp/etc..
    editted: solved this one.. setting its visible property in code and not in the design view should do the trick (TextBox.Visible = False)

    3rd question: <---- not yet solved T_T
    Code:
    ' INSERT TO TABLE
    
    ' RETRIEVE TO TABLE THEN BIND TO DATAGRIDVIEW
    how can i bind values straight to a datagridview..? as you can see in my code, before binding it to a datagridview, i insert it then retrieve to table the values i want to bind in my datagridview..

    4th question: <---- not yet solved too T_T

    before, this are my records in tbl_MGLTransaction (Figure 1)
    now, ive added a new record.. (figure 2)
    when i run code, the output is the same as before.. (figure 3)
    how can i make it to look like figure 4 ?


    someone pls check my code.. tnx..
    Attached Images Attached Images  
    Last edited by savior14; Feb 3rd, 2008 at 10:54 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    have another look at your code

    vb Code:
    1. If dtpDate.Value >= dateThirty And dtpDate.Value <= dateThirty Then

    that'll never be executed. it can't be >= and <= at the same time unless its =

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    Quote Originally Posted by .paul.
    have another look at your code

    vb Code:
    1. If dtpDate.Value >= dateThirty And dtpDate.Value <= dateThirty Then

    that'll never be executed. it can't be >= and <= at the same time unless its =
    still the same output sir..

    changed this one:
    If dtpDate.Value >= dateThirty And dtpDate.Value <= dateThirty

    to:
    If dtpDate.Value = dateThirty And dtpDate.Value <= dateThirty

    also the rest..

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    try this

    vb Code:
    1. Dim tempDate As DateTime = dtpDate.Value
    2. Dim dateThirty As Date = tempDate.AddDays(30)
    3. Dim dateSixty As Date = tempDate.AddDays(60)
    4. Dim dateNinety As Date = tempDate.AddDays(90)
    5.  
    6. Dim oneToThirtyAmount As New Integer
    7. Dim thirtyToSixtyAmount As New Integer
    8. Dim sixtyToNinetyAmount As New Integer
    9. Dim moreThanNinetyAmount As New Integer
    10.  
    11. If dtpDate.Value >= tempDate And dtpDate.Value <= dateThirty Then
    12.    oneToThirtyAmount = txtAmount.Text
    13.    thirtyToSixtyAmount = 0
    14.    sixtyToNinetyAmount = 0
    15.    moreThanNinetyAmount = 0
    16.  
    17. ElseIf dtpDate.Value > dateThirty And dtpDate.Value <= dateSixty Then
    18.    oneToThirtyAmount = 0
    19.    thirtyToSixtyAmount = txtAmount.Text
    20.    sixtyToNinetyAmount = 0
    21.    moreThanNinetyAmount = 0
    22.  
    23. ElseIf dtpDate.Value > dateSixty And dtpDate.Value <= dateNinety Then
    24.    oneToThirtyAmount = 0
    25.    thirtyToSixtyAmount = 0
    26.    sixtyToNinetyAmount = txtAmount.Text
    27.    moreThanNinetyAmount = 0
    28.  
    29. ElseIf dtpDate.Value > dateNinety Then
    30.    oneToThirtyAmount = 0
    31.    thirtyToSixtyAmount = 0
    32.    sixtyToNinetyAmount = 0
    33.    moreThanNinetyAmount = txtAmount.Text
    34.  
    35. End If

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    but, i just noticed

    vb Code:
    1. Dim tempDate As DateTime = dtpDate.Value

    if dateThirty = dtpDate.Value + 30 days & dateSixty = dtpDate.Value + 60 then your if statements are incorrect. dtpDate.Value is never going to be anything but tempDate

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    what ive done is this..
    Code:
            Dim tempDate As DateTime = dtpDate.Value
            Dim dateThirty As Date = tempDate.AddDays(30)
            Dim dateSixty As Date = tempDate.AddDays(60)
            Dim dateNinety As Date = tempDate.AddDays(90)
    
            Dim oneToThirtyAmount As New Integer
            Dim thirtyToSixtyAmount As New Integer
            Dim sixtyToNinetyAmount As New Integer
            Dim moreThanNinetyAmount As New Integer
    
            If tempDate <= dateThirty Then
                oneToThirtyAmount = txtAmount.Text
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf tempDate > dateThirty And tempDate <= dateSixty Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = txtAmount.Text
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf tempDate > dateSixty And tempDate <= dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = txtAmount.Text
                moreThanNinetyAmount = 0
    
            ElseIf tempDate > dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = txtAmount.Text
    
            End If
    it seems the same to your code.. here is the ouput..

    seems like there's something wrong with the code..(but there's a little improvement lol xD)
    Attached Images Attached Images  

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    Dim tempDate As DateTime = dtpDate.Value
    Dim dateThirty As Date = tempDate.AddDays(30)

    tempDate is never going to be greater than dateThirty because dateThirty = tempDate.AddDays(30)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    yeah right!! i got your point!! tnx to that..(currently thinking what to replace)
    *swt* silly me.. hmmm.. what must be.. uhmm, errrr, a little help sir
    Last edited by savior14; Feb 3rd, 2008 at 10:16 AM.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    if you want to know if 'now' is between tempDate + dateThirty

    vb Code:
    1. If now >= tempDate and now <= dateThirty Then

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    Quote Originally Posted by .paul.
    if you want to know if 'now' is between tempDate + dateThirty

    vb Code:
    1. If now >= tempDate and now <= dateThirty Then
    you know what? THANK YOU!! i mean THANK YOU THANK YOU!!! that solves my problem!!! tnx again!!(rated you lol )

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    Here's the updated code.
    Code:
            txtPayee.Visible = False
            txtAmount.Visible = False
            dtpDate.Visible = False
            objDataAdapter.SelectCommand = New SqlCommand()
            objDataAdapter.SelectCommand.Connection = objConnection
            objDataAdapter.SelectCommand.CommandText = _
            "SELECT MGL_Payee, MGL_TotalAmount, MGL_ReferenceDate FROM tbl_MGLTransaction"
            objDataAdapter.SelectCommand.CommandType = CommandType.Text
    
            Dim objDataSet As New DataSet()
            objConnection.Open()
            objDataAdapter.Fill(objDataSet, "tbl_MGLTransaction")
            objDataView = New DataView(objDataSet.Tables("tbl_MGLTransaction"))
    
            'Clear then Bind
            txtPayee.DataBindings.Clear()
            txtAmount.DataBindings.Clear()
            dtpDate.DataBindings.Clear()
    
            txtPayee.DataBindings.Add("Text", objDataView, "MGL_Payee")
            txtAmount.DataBindings.Add("Text", objDataView, "MGL_TotalAmount")
            dtpDate.DataBindings.Add("Value", objDataView, "MGL_ReferenceDate")
            objConnection.Close()
    
            Dim tempDate As DateTime = dtpDate.Value
            Dim dateThirty As Date = tempDate.AddDays(30)
            Dim dateSixty As Date = tempDate.AddDays(60)
            Dim dateNinety As Date = tempDate.AddDays(90)
    
            Dim oneToThirtyAmount As New Integer
            Dim thirtyToSixtyAmount As New Integer
            Dim sixtyToNinetyAmount As New Integer
            Dim moreThanNinetyAmount As New Integer
    
            If Now >= tempDate And Now <= dateThirty Then
    
                oneToThirtyAmount = txtAmount.Text
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateThirty And Now <= dateSixty Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = txtAmount.Text
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateSixty And Now <= dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = txtAmount.Text
                moreThanNinetyAmount = 0
    
            ElseIf Now > dateNinety Then
                oneToThirtyAmount = 0
                thirtyToSixtyAmount = 0
                sixtyToNinetyAmount = 0
                moreThanNinetyAmount = txtAmount.Text
    
            End If
    
            'Bind
            'Insert To Table
            'Retrieve To Table
            'Bind To DataGrid
            'Delete Record From Table
    
            Dim objConnection2 As SqlConnection = New _
            SqlConnection("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            Dim objCommand2 As SqlCommand = New SqlCommand()
            objCommand2.Connection = objConnection2
            objCommand2.CommandText = "INSERT INTO tbl_ARAging " & _
            "(Payee, TotalAmount, ReferDate, OneToThirty, ThirtyToSixty, SixtyToNinety, MoreThanNinety) " & _
            "VALUES(@Payee, @TotalAmount, @ReferDate, @OneToThirty, @ThirtyToSixty, @SixtyToNinety, @MoreThanNinety)"
            objCommand2.Parameters.AddWithValue("@Payee", txtPayee.Text)
            objCommand2.Parameters.AddWithValue("@TotalAmount", txtAmount.Text)
            objCommand2.Parameters.AddWithValue("@ReferDate", dtpDate.Value)
            objCommand2.Parameters.AddWithValue("@OneToThirty", oneToThirtyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@ThirtyToSixty", thirtyToSixtyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@SixtyToNinety", sixtyToNinetyAmount.ToString)
            objCommand2.Parameters.AddWithValue("@MoreThanNinety", moreThanNinetyAmount.ToString)
            objConnection2.Open()
            objCommand2.ExecuteNonQuery()
            objConnection2.Close()
    
            Dim objConnection3 As New SqlConnection _
          ("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            objDataAdapter3.SelectCommand = New SqlCommand()
            objDataAdapter3.SelectCommand.Connection = objConnection3
            objDataAdapter3.SelectCommand.CommandText = ("select Payee, TotalAmount, ReferDate, OneToThirty, ThirtyToSixty, SixtyToNinety, MoreThanNinety FROM tbl_ARAging")
    
            objDataAdapter3.SelectCommand.CommandType = CommandType.Text
    
            Dim objDataSet3 As New DataSet()
            objConnection3.Open()
            objDataAdapter3.Fill(objDataSet3, "tbl_ARAging")
            objDataView3 = New DataView(objDataSet3.Tables("tbl_ARAging"))
    
            grdAuthorTitles.DataSource = objDataSet3
            grdAuthorTitles.DataMember = "tbl_ARAging"
    
            grdAuthorTitles.Columns(0).HeaderText = "Payee"
            grdAuthorTitles.Columns(1).HeaderText = "TotalAmount"
            grdAuthorTitles.Columns(2).HeaderText = "Reference Date"
            grdAuthorTitles.Columns(3).HeaderText = "1 - 30"
            grdAuthorTitles.Columns(4).HeaderText = "31 - 60"
            grdAuthorTitles.Columns(5).HeaderText = "61 - 90"
            grdAuthorTitles.Columns(6).HeaderText = ">90"
    
            objConnection3.Close()
            Dim objConnection4 As New SqlConnection _
          ("Data Source=MORETHANENOUGH\SQLEXPRESS;Initial Catalog=accountingdb;Integrated Security=True")
            Dim objCommand4 As SqlCommand = New SqlCommand()
            objCommand4.Connection = objConnection4
            objCommand4.CommandText = ("DELETE FROM tbl_ARAging")
    
            objConnection4.Open()
            objCommand4.ExecuteNonQuery()
            objConnection4.Close()
    last problem..
    before, this are my records in tbl_MGLTransaction (Figure 1)
    now, ive added a new record.. (figure 2)
    when i run code, the output is the same as before.. (figure 3)
    how can i make it to look like figure 4 ?

    it didnt add my 2nd record to datagridview..
    Attached Images Attached Images  
    Last edited by savior14; Feb 3rd, 2008 at 11:24 AM.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Comparing Dates

    i'm not sure what you're asking.
    i'm not an expert with databases. you could try the database development forum. ask a moderator to move this thread

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    ooohhh.. i seee.. btw, tnx again... you've been a big help to me hope a moderator would see this..

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    117

    Re: [2005] Comparing Dates

    updated 1st post.. someone pls.. need help.. pls see my 3rd and 4th question.. tnx..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width