(Resolved) Allways get the last record in the database
How do I ensure I allways get the last record in the database? While just using a simple Select Statement it seems to do it by default but I need to make sure it does everytime.
Code:
Dim cnn As New OleDbConnection
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cnn.ConnectionString = _
My.Settings.Coupon_BarcodeConnectionString
cmd = cnn.CreateCommand
cmd.CommandText = "SELECT MarketingPiece, [Number] " & _
"FROM tblMarketingPiece "
Try
cnn.Open()
dr = cmd.ExecuteReader
While dr.Read()
lblMPN.Text = CStr(dr("MarketingPiece"))
lblCN.Text = CStr(dr("Number"))
End While
dr.Close()
cnn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message)
Exit Sub
End Try
Re: Allways get the last record in the database
Use the SQL command: ORDER BY
Re: Allways get the last record in the database
OK that was an embarrassingly simple solution. For some reason I have a VB.Net tendency to make things a lot more complicated then they need to be.
Thanks