I am new in vb.NET and SQL. I want to view the latest input in my vb.NET program. How would I do it? Where bed number is auto-increment. Currently, this do record the changes in the database but when I want to view the details the label remains empty which it should be.
This is my code:
Dim SQLStatement As String = "SELECT name, age, date_of_confinement,type_of_sickness, " _
"type_of_IV_fluid, number_of_bottles, drop_rate " _
"FROM patient WHERE bednumber=1"
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
'--read the records in database in phpmyadmin gui---
Dim myReader As MySqlDataReader = cmd.ExecuteReader
If myReader.Read Then
ViewInfo.lblName.Text = myReader.GetString(0)
ViewInfo.lblAge.Text = myReader.GetString(1)
ViewInfo.lblDate.Text = myReader.GetString(2)
ViewInfo.lblSickness.Text = myReader.GetString(3)
ViewInfo.lblFluid.Text = myReader.GetString(4)
ViewInfo.lblBottle.Text = myReader.GetString(5)
ViewInfo.lblDrop.Text = myReader.GetString(6)
myReader.Close()
End If
End With
Thanks!
Try to change the SQL statement in this way:
This will sort the patient table on
bednumberin descending order (so the last inserted record is on top) then get this first record (TOP 1).Of course I suppose that
bednumberis a numeric column with values autogenerated sequentially by the database in rough order of insertion.