Show text in a TextBox of XtraUserControl

0

I have a GridControl in a form and a XtraUserControl , in the event DoubleClick of the grid I load some data to a textbox of XtraUserControl , it brings the data correctly but it does not show them.

This is the method I use:

Public Sub CargaConsulta(ByVal id As Integer, txt As TextBox)
    Dim sConex As New SqlConnection
    Dim sql As String = "SELECT ComandoSql 
                         FROM dbo.Ad_Consultas
                         WHERE Sec_Consulta = @id"
    CadCon = Me.CadConex
    sConex.ConnectionString = CadCon
    Dim sqlComan As New SqlCommand(sql, sConex)
    sqlComan.Parameters.AddWithValue("@id", id)
    Try
        sConex.Open()
        Dim leer As SqlDataReader = sqlComan.ExecuteReader
        If leer.Read Then
            txt.Text = Convert.ToString(leer("ComandoSql"))
        End If
        leer.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

From here I call CargarConsulta :

Private Sub VistaConsultas_DoubleClick(senede As Object, e As EventArgs)Handles VistaConsultas.DoubleClick
    CargarConsulta(id, xtrausercontrol.txtscripsql)        
End Sub

The issue is that the follow-up shows me the value that brings normal but does not load it.

Note: I've already done tests with a button to assign value with a click and it did not work either, I do not know if these controls have any kind of restrictions.

    
asked by avargasma 27.04.2016 в 23:22
source

1 answer

2

You should not pass any control to the method to assign its value, but you should implement something like

Public Sub CargaConsulta(ByVal id As Integer) As String

    Using sConex As New SqlConnection(Me.CadConex)
        sConex.Open()

        Dim sql As String = "SELECT ComandoSql 
                             FROM dbo.Ad_Consultas
                             WHERE Sec_Consulta = @id"

        Dim sqlComan As New SqlCommand(sql, sConex)
        sqlComan.Parameters.AddWithValue("@id", id)

        Dim leer As SqlDataReader = sqlComan.ExecuteReader
        If leer.Read Then
            Return Convert.ToString(leer("ComandoSql"))
        End If

        Return ""

    End Using

End Sub

You will see that the method returns a string and from the event you assign it to the control

Private Sub VistaConsultas_DoubleClick(senede As Object, e As EventArgs)Handles VistaConsultas.DoubleClick

    Try

        Dim command As String = CargarConsulta(id)  

        xtrausercontrol.txtscripsql.Text = command

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

In this way the responsibility of the method is to return a result obtained from the db. It will be the event who will assign it to the control

    
answered by 28.04.2016 в 16:42