Show result in textbox linq vb.net

2

This is my query you want to know how to pass each field to the textbox

 Dim query = From Q In Ejecutarconsulta("Select * from secreg where tabla='" _
                                         + tabla.Trim() + "' and codempresa='01'" ).AsEnumerable()
                                     Select New With {.tabla = Q.Field(Of String)("Tabla").Trim(),
                                                     .Secuencia = Q.Field(Of String)("Secuencia").Trim(),
                                                      .Letra = Q.Field(Of String)("Secuencia").Trim()}
    
asked by JOSE ANGEL RAMIREZ HERNANDEZ 24.07.2016 в 19:45
source

1 answer

1

When you create a linq this returns a list or collection of values, if you have several items that show the normal would be that you assign the result to a list control such as a ListView or DataGridView.

Now if you want to assign it to simple TextBoxs you will have to take a single item

Dim query As String = String.Format("Select * from secreg where tabla='{0}' and codempresa='01'", tabla.Trim())
Dim data = Ejecutarconsulta(query).AsEnumerable()

Dim result = (From Q In data
             Select New With {.tabla = Q.Field(Of String)("Tabla").Trim(),
                             .Secuencia = Q.Field(Of String)("Secuencia").Trim(),
                              .Letra = Q.Field(Of String)("Secuencia").Trim()}).FirtOrDefault()


If result IsNot Nothing Then
    txtTabla.Text = result.tabla
    txtSecuencia.Text = result.Secuencia
    txtLetra.Text = result.Letra
End If

As you will notice, it is good to separate the lines of code a little in several operations, then when generating the linq I use the FirstOrDefault () to take run only data to show in the textbox

    
answered by 26.07.2016 / 05:38
source