[英]How to get database value on label in vb.net?
I am beginner level programmer. 我是初学者级程序员。 Actually i have used two combo box named as "Category" and "Location".
实际上我已经使用了两个组合框,分别命名为“类别”和“位置”。 When i will click on submit then it should display the category of chemicals and location respectively from database on the labels itself.
当我单击提交时,它应该在标签本身上分别显示数据库中的化学物质类别和位置。
I think you might be looking for something like this? 我想您可能正在寻找这样的东西?
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet
connetionString = "ConnetionString;"
connection = New SqlConnection(connetionString)
Try
connection.Open()
adapter = New SqlDataAdapter("Select column1, column2, column3, column4 from Table1 where Id='" & TextBox9.Text & "'", connection)
adapter.Fill(ds)
connection.Close()
If ds.Tables(0).Rows.Count > 0 Then
label1.Text = "blablabla" & ds.Tables(0).Rows(0)("column1").ToString()
label2.Text = "blablabla" & ds.Tables(0).Rows(0)("column2").ToString()
label3.Text = "blablabla" & ds.Tables(0).Rows(0)("column3").ToString()
label4.Text = "blablabla" & ds.Tables(0).Rows(0)("column4").ToString()
End If
Catch ex As Exception
Form4.TextBox1.Text = "Failed to connect to database"
Form4.Show()
End Try
Return False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.