简体   繁体   中英

Retrieve data from database to multiple textbox

When I retrieve data from my Access database to a multiline TextBox , it shows all my data in the same line. In the DataGridView everything is fine and shows line by line. How to make my textboxes to show data line by line as well?

con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from data where [ID] like(" + textBox9.Text + ")";
cmd.Connection = con;
var reader = cmd.ExecuteReader();

while (reader.Read())
{
    textBox1.Text = reader["Target Name"].ToString();
}
textBox1.Multiline = true;

textBox1.Text += reader["Target Name"].ToString() + Environment.NewLine;

Set MultiLine property to true and and a new line while setting textBox1.Text with adding Environment.NewLine at the end.

This should give the TextBox a Grid/Table appearance:

while (reader.Read())
{
    textBox1.Text = reader.getString(0)+"\t"+reader.getString(1)+"\r\n"; //in the case the table 'data' has 2 columns
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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