Sort field or date expired notifications, database

1

I do not know about database, I'm using one in Visual Studio (the default SQL called "Services-based Database"), I already integrated it into the form and made up the query fields.

But it has a field of one of the tables that would be dated, that date is like a 'loan', and it expires (in a week, as an example).

So here comes the doubt (I researched and did not find anything about it).

The question is:

How do I sort a table of this database by the data field, showing the records of the data field oldest to the newest?

Another doubt (this is more advanced), but the first one is enough for me (I'm humble kk), it's like, this data field, as I said, is like a loan, so I wanted to know, taking the example registration:

"Nome: José", "Data do empréstimo: 23/06/2015"

In this table, as I've estimated the expiration date is a week, the expiration would be today, so how do I get that record from the database and store it in a variable (to be displayed in another form)?

The other field:

"Nome: João", "Data do empréstimo: 24/06/2015"

The maturity would be tomorrow, so tomorrow he would send that record to the other form automatically, as if it were a due notification.

    
asked by anonymous 30.06.2015 / 20:06

2 answers

1

At first just sort the dates you can use order by .

Ex: SELECT * FROM usuarios ORDER BY dataemprestimo ASC

desc for descending and asc for ascending, how to get the date that expires, in the Load function of the form, you can call a function to do this, you can create a sql in the bank something like:

Ex: SELECT * FROM usuarios where dataemprestimo > datalimite

So you would have all the records that exceeded the deadline, detail, to work that query you need a field that is stored the deadline for the user to return the product, simple thing to do in insert and programming at the time of registration.

NOTE: If you give me the name of the tables, I put the function here.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   notificarUsuarios()
End Sub

 Private Sub notificarUsuarios()
 se quiser apenas armazenar 1 data, mais vc pode jogar em um datagrid
     Dim nomeDoUsuario As String = nomeDataSet.Tables("usuarios").Rows(0)("usuario")
     Dim dataVencida As String = nomeDataSet.Tables("usuarios").Rows(0)("dataexpira")
 End Sub
    
30.06.2015 / 20:38
1

If you want the ANCIENT date and not the NEW one, you want up and not descend .

SELECT * FROM Emprestimo
ORDER BY dataemprestimo ASC

SqlFiddle Example

On your second problem, you can use the Sql Server variable to get the current day and time GETDATE() .

In this way, in a table, the due dates are:

SELECT * FROM Emprestimo
WHERE datalimite <= GETDATE()
ORDER BY dataemprestimo ASC

And in the table the ones that did not win are still:

SELECT * FROM Emprestimo
WHERE datalimite > GETDATE()
ORDER BY dataemprestimo ASC
    
30.06.2015 / 20:44