簡體   English   中英

如何將結果Sqldatareader多行填充到文本框

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

如何從循環數組sqldatareader到變量或文本框填充結果? 我有一個表和一些基於行的多行代碼,例如:

在此處輸入鏈接說明

以及如何在此處填充文本框:

在此處輸入鏈接說明

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

謝謝

您可以嘗試這樣的事情。 假設文本框被依次命名為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