我是vb.NET和SQL的新手。我想查看我的vb.NET程序中的最新输入。我该怎么办?床号自动增量。目前,这会记录数据库中的更改,但是当我想查看详细信息时,标签仍然是空的,应该是。
这是我的代码:
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
谢谢!
答案 0 :(得分:1)
尝试以这种方式更改SQL语句:
Dim SQLStatement As String = "SELECT TOP 1 name, age, date_of_confinement,type_of_sickness, " _
"type_of_IV_fluid, number_of_bottles, drop_rate " _
"FROM patient ORDER BY bedumber DESC"
这将按照bednumber
的降序对患者表进行排序(因此最后插入的记录位于顶部),然后获取第一条记录(TOP 1)。
当然,我认为bednumber
是一个数字列,数据库按照粗略的插入顺序自动生成值。
答案 1 :(得分:0)
为了显示最新的输入,我将在我的查询中执行此操作
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 badnumbre=(SELECT MAX(bednumber) from patien )"
我使用Sub查询
我希望它运行良好:))