Sql 通过VisualBasic.NET中的对象名称引用文本框

Sql 通过VisualBasic.NET中的对象名称引用文本框,sql,arrays,vb.net,object,Sql,Arrays,Vb.net,Object,如何使用对象的值(例如字符串)引用Visual Basic.net中表单上文本框的名称?我希望能够从SQL数据库中获取信息,并根据表单上的名称将它们放在相应的文本框中(例如,将字段fSynopsis的信息放在文本框txtSynopsis.text中) 下面的代码是我目前正在使用的代码 Private Sub DataGridView1_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgv

如何使用对象的值(例如字符串)引用Visual Basic.net中表单上文本框的名称?我希望能够从SQL数据库中获取信息,并根据表单上的名称将它们放在相应的文本框中(例如,将字段fSynopsis的信息放在文本框txtSynopsis.text中)

下面的代码是我目前正在使用的代码

Private Sub DataGridView1_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvResults.CellMouseClick
    ' Set values in the text boxes to both corresponding to the film.

    Dim strFields() As String = {"fSynopsis", "fGenre", "fSynopsis", "fAgeRating", "fActorsActresses", "fWebRating", "fNoReservations", "fWeeksRunning"}
    'Create an array containing the names of the fields in the database.

    Dim Con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ApplicationData.accdb;Persist Security Info=False;")
    Con.Open() 'Open the connection
    Dim Cmd As New OleDbCommand(StringBuilderCommand("fAgeRating", "Films", dgvResults.CurrentCell.Value, "fName"), Con) 'Create a string by calling the StringBuilderCommand to combine the parameters together with quotes.

    Cmd.CommandType = CommandType.Text
    Dim Rdr As OleDbDataReader = Cmd.ExecuteReader()

    Dim intCount As Integer = 0 ' Create a loop variable.
    Do While Rdr.Read() ' While this statement is 'TRUE', e.g. there is a valid record.

        strResult = "txt" & strFields(intCount).Replace("f", "") 'Remove any instances of 'f', e.g. the prefix of the string.

        strResult.Text = Rdr.Item(strFields(intCount).ToString)
        'Set the text-box to the correct value from the database.
        ' This will allow me to go through several text boxes, and grab their corresponding  values from the database.

        intCount += 1
    Loop
我真的非常感谢任何可以提供的帮助,谢谢

试试这段代码

 CType( Me.Controls("strResult"),TextBox).Text = Rdr.Item(strFields(intCount).ToString)