[英]Show last row of database MySQL VB.net
How can I show the last row of data in database? 如何显示数据库中的最后一行数据?
I have this code here but it only shows the first data row in database 我在这里有此代码,但它仅显示数据库中的第一个数据行
Dim cnPodaci AsNew SqlConnection
cnPodaci.ConnectionString = "your connection string"
cnPodaci.Open()
Dim cm AsNew SqlCommand
cm.CommandText = "SELECT * FROM TABLE"
cm.Connection = cnPodaci
Dim dr As SqlDataReader
dr = cm.ExecuteReader
If dr.HasRows Then
dr.Read()
txtBox1.text = dr.Item("ColumnName1")
txtBox2.text = dr.Item("ColumnName2")
dr.Close()
EndIf
cnPodaci.Close()
You may add an "ORDER BY" to your sql. 您可以在SQL中添加“ ORDER BY”。 Like 喜欢
cm.CommandText = "SELECT * FROM TABLE ORDER BY XX desc"
Assuming XX is the name of the column which increases for every new row. 假设XX是列名,每增加一个新行就增加一次。
Edit: 编辑:
consider: 考虑:
cm.CommandText = "SELECT * FROM TABLE ORDER BY XX desc limit 1"
It will return the last row, having chosen what XX is. 选择了XX后,它将返回最后一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.