Answered Array as textbox

Mimi

Member
Joined
Jul 13, 2020
Messages
9
Programming Experience
Beginner
I have array
C#:
string[] pole = new string[3] {textBox1.Text, textBox2.Text, textBox3.Text };

an I need insert data from database to textbox1

C#:
            SqlCommand cmd = new SqlCommand("SELECT *  FROM database ", con);
            SqlDataReader dr = cmd.ExecuteReader();

I tried it but it doesn't work for me

C#:
pole[0] = dr.GetValue(1).ToString();
 
Your array only contains the Text strings. You can put the textboxes in the array:
C#:
TextBox[] pole = { textBox1, textBox2, textBox3 };
and then get the TextBox element and set its Text property:
C#:
pole[0].Text = dr.GetValue(1).ToString();
 

Latest posts

Back
Top Bottom