get one column value based on another column value RRS feed

  • Question

  • User1717218719 posted

    I have the following code:

    I am looking to get the trn column value if the tktdoc number is = tot the value in the textbox. I am not sure how to get the. there are many mistakes in my code im sure but this is my initial attempt

    objTrnID in my code. any help would be great.

      Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim strTktNbr = txtSearch.Text
            Dim objTrnID As Object = GetTrnID(strTktNbr)
            If Not IsDBNull(objTrnID) Then
                Call GetTrnsHeadDataBase(CInt(objTrnID))  '--Trn ID
            End If
        Public Function GetTrnID(ByVal objTrnID As Object) As Object
            conConn = New SqlConnection(GblSqlCon)
            '--Read from Database
            comComm = New SqlCommand
            With comComm
                .Connection = conConn
                .CommandType = CommandType.Text
                .CommandText = "Select * " &
                "From tbl" &
                "WHERE (TktID = TktID) AND (TrnID = TrnID)"
                .Parameters.AddWithValue("@TktID", txtSearch.Text)
                .Parameters.AddWithValue("@TrnID", objTrnID)
            End With
            '    If Not String.IsNullOrEmpty(txtSearch.Text) Then
            '        Return objTrnID
            '    Else
            '        Return Nothing
            '    End If
        End Function

    Tuesday, August 13, 2019 3:00 PM


  • User288213138 posted

    Hi E.RU,

    According to your description, I made a demo for your reference.

    I get the one column value from textbox, then use the query statement “select from where” to query the value of another column.

    The code:

    Public GblSqlCon As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Public Sub GetTrnID(ByVal objTrnID As String)
            Dim conConn As SqlConnection = New SqlConnection()
            Dim comComm As SqlCommand = New SqlCommand()
            conConn = New SqlConnection(GblSqlCon)
            comComm = New SqlCommand()
            If True Then
                Dim withBlock = comComm
                withBlock.Connection = conConn
                withBlock.CommandType = CommandType.Text
                withBlock.CommandText = String.Format("SELECT * FROM Customer WHERE Name='{0}'", objTrnID)
                Dim sdr As SqlDataReader = comComm.ExecuteReader()
                While sdr.Read()
                    Dim s1 As String = Convert.ToString(sdr("Country"))
                End While
            End If
        End Sub
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim strTktNbr = TextBox1.Text
        End Sub

    The result:

    Best regards,


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2019 3:16 AM