当我从Access数据库中检索数据到多行TextBox
时,它会在同一行显示我的所有数据。在DataGridView
中,一切都很好,并逐行显示。如何使我的文本框也逐行显示数据?
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();
}
答案 0 :(得分:1)
textBox1.Multiline = true;
textBox1.Text += reader["Target Name"].ToString() + Environment.NewLine;
将MultiLine
属性设置为true,并在设置textBox1.Text
时设置新行,并在末尾添加Environment.NewLine
。
答案 1 :(得分:0)
这应该给TextBox一个Grid / Table外观:
while (reader.Read())
{
textBox1.Text = reader.getString(0)+"\t"+reader.getString(1)+"\r\n"; //in the case the table 'data' has 2 columns
}