Question Compare DB Cell Value and System Time

sh250080

New member
Joined
Feb 6, 2009
Messages
3
Programming Experience
3-5
Hello Im making a scheduling program and I have three columns in my DB AgentName, Type, and DueBack. My DueBack Column will have a value of like 10:30 PM. Im needing to see if the Column value is the same as the System Time then it will delete the value from the DB and update the DGV> I know hwo to do everything else besides Compare and Delete. Below Ive pasted what Ive tried any help is appreciated.

VB.NET:
        For Each row As DataGridViewRow In dgb1.Rows
            Dim delete As DateTime
            delete = row.Cells(2).Value.ToString
            If System.DateTime.Now.ToShortTimeString = delete Then
                ' Dim connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & My.Settings.DBcon.ToString)
                Dim command As New OleDbCommand("DELETE FROM type WHERE DueBack=@DueBack", connection)
                '  Dim row1 = System.DateTime.Now.ToShortTimeString = 
                command.Parameters.Add(New OleDbParameter("@DueBack", ))
                connection.Open()
                command.ExecuteNonQuery()
                connection.Close()

                adapter.Fill(dt)
                dgb1.DataSource = dt
            End If
        Next

I have this code in a timer and if the system time matches the Column Value it seems like it tries to add more rows and I end up with a scrollbar looking thing and it freezes until the time changes to the next minute. Im unsure what value I should for

command.Parameters.Add(New OleDbParameter("@DueBack", )) - I thought the delete but it didnt work. Any ideas?
 
Why not just run the query:

DELETE FROM type WHERE DueBack=?

and set the parameter to the current time:

cmd.Parameters("yourParamName").Value = DateTime.Now
cmd.ExecuteNonQuery()


you do not do this for every row. you do it ONCE per interval
-

Lastly if all this is in a DGV, then why don't you just .Delete() the row from the datatable as you pass, then at the end, call myTableAdapter.Update(theDataTable) to delete the rows?

It sounds like youre getting stuck with your data access code. Read the DW2 link in my signature, section Creating a Simple Data App
 
Thank for that it seems to work but now I have another problem. I used this code:
VB.NET:
        Dim command As New OleDbCommand("DELETE FROM type WHERE DueBack=?", connection)
        '  Dim row1 = System.DateTime.Now.ToShortTimeString = 
        command.Parameters.Add(New OleDbParameter("?", System.DateTime.Now.ToShortTimeString))
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()
        adapter.Fill(dt)
        dgb1.DataSource = dt

Now it adds a duplicate row of the row thats not being deleted and after the row thats supposed to delete does the duplicate row is still there.
 

Latest posts

Back
Top