2016-05-20 6 views
0

ループ配列sqldatareaderの結果をvarriableまたはtextboxに取り込む方法は? 私はここのような複数行のコードを、ベーステーブルといくつかの行を持っている:Sqldatareader複数行をテキストボックスに取り込む方法

enter link description here http://i66.tinypic.com/2ni5ocj.jpg

、どのように、ここのようにテキストボックスために移入するために:

enter link description here http://i67.tinypic.com/33vozr7.jpg

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 

はありがとうございました

答えて

0

あなたはこのようなものを試すことができます。テキストボックスの名前は、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]; 
関連する問題