As a newbie I'm growing old trying to figure out how to return a string value from an sql select command with vb code behind. The program I have is below. Essentially what I'm trying to do is extract the value in the DisplayName field in table BuildFields (with WHERE conditions) and place it into the text field of a label within a formview template. It doesn't seem like it should be difficult and I'm sure I'm missing something. Does anybody have any ideas or see what I'm doing wrong? This isn't returning anything. Thanks.
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
Dim dt As New DataTable()
Dim conCString As String = ConfigurationManager.ConnectionStrings("conCString").ConnectionString
Dim lbl As Label = FormView1.FindControl("Label1")
Dim sqlConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conCString").ConnectionString)
Dim cmd As New SqlCommand
cmd.CommandText = "SELECT [DisplayName] FROM [BuildFields] WHERE ([TableID] = N'Capacitors') AND (ColumnID = N'UserField01') ORDER BY [ColumnID]"
cmd.CommandType = CommandType.Text
cmd.Connection = SqlConnection
Try
SqlConnection.Open()
Dim result As String
result = cmd.ExecuteScalar()
lbl.Text = result
sqlConnection.Close()
Catch ex As Exception
End Try
End Sub