Updating UsageTime in SQL Server via Visual Studio

2019-09-21 08:44发布

问题:

I want to update the UsageTime when the time ticks per minute, couldn't get the right code.

Private Sub LBLTime_TextChanged(sender As Object, e As EventArgs) Handles LBLTime.TextChanged

    con.ConnectionString = My.Settings.Finals_DBConnectionString
    cmd.Connection = con
    con.Close()
    con.Open()
    cmd.CommandText = "update tbl_transaction set usagetime = @ut, remainingtime = @rt"
    cmd.Parameters.Clear()
    cmd.Parameters.AddWithValue("ut", +1)
    cmd.Parameters.AddWithValue("rt", -1)
    cmd.Parameters cmd.ExecuteNonQuery()
    End With
End Sub

回答1:

try this.

update tbl_transaction set usagetime = usagetime+1 , remainingtime = remainingtime -1 

Also don't see any "where" in your sql. It's not a good practice