我想自动将数据库中的价格插入到我的应用程序中的标签中。因此,对于每个项目,它会自动保持价格最新,我该怎么做?我在网上找到了这个功能:
Public Shared Function GetRecord(sql As String) As String
Dim result As String
connection.Open()
Dim command As New SqlCommand(sql, connection)
Try
If command.ExecuteScalar IsNot System.DBNull.Value Then
result = command.ExecuteScalar
Else
result = ""
End If
Catch ex As Exception
Throw ex
Finally
connection.Close()
End Try
Return result
End Function
然后为我提出的每个标签:
Dim sql As String = "SELECT price from product where product_id = 1"
lblGateu.Text = sql.GetRecord(sql)
但这不起作用。