简体   繁体   English

如何将结果Sqldatareader多行填充到文本框

[英]How to populate result Sqldatareader multiple row to textbox

How to populate result from looping array sqldatareader to a varriable or textbox? 如何从循环数组sqldatareader到变量或文本框填充结果? I have a table and some row based a code for multiple rows, like here: 我有一个表和一些基于行的多行代码,例如:

在此处输入链接说明

and how to populate to textbox like here : 以及如何在此处填充文本框:

在此处输入链接说明

Dim cmd2 As New SqlCommand("Select * from SI where id_group='211'")
    dr = cmd.ExecuteReader
         While dr.Read()

        'what is the right code for this case

    End While

Thank You 谢谢

You could try something like this. 您可以尝试这样的事情。 Assuming that the textboxes are named sequentially as txtName1, txtName2, txtBook1, txtBook2 etc. and the field names are "name", "book" etc. 假设文本框被依次命名为txtName1,txtName2,txtBook1,txtBook2等,并且字段名称为“名称”,“书”等。

        int count = 0;
        Dictionary<string, string> TextBoxValues = new Dictionary<string,string>();
        while(dr.Read())
        {
            count++;
            TextBoxValues.Add("txtName" + count, dr["name"].ToString());
            TextBoxValues.Add("txtBook" + count, dr["book"].ToString());
        }

        txtName1.Text = TextBoxValues[txtName1.ID];
        txtName2.Text = TextBoxValues[txtName2.ID];

        txtBook1.Text = TextBoxValues[txtBook1.ID];
        txtBook2.Text = TextBoxValues[txtBook2.ID];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM