C# 在多行文本框中逐行显示文本
大家好,当我从access数据库检索数据到我的文本框多行文本框时,数据在一行旁边显示我希望任何一行都在它的行中例如,我的access字段中有5行,但在我的文本框中显示同一行中的所有数据我应该做些什么C# 在多行文本框中逐行显示文本,c#,c#-4.0,c#-3.0,facebook-c#-sdk,c#-2.0,C#,C# 4.0,C# 3.0,Facebook C# Sdk,C# 2.0,大家好,当我从access数据库检索数据到我的文本框多行文本框时,数据在一行旁边显示我希望任何一行都在它的行中例如,我的access字段中有5行,但在我的文本框中显示同一行中的所有数据我应该做些什么 OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\db\\it.accdb"); con.Open()
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\db\\it.accdb");
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["Name"].ToString();
textBox20.Text = reader["Description"].ToString();
// ----------------------------------------------
// These doesn't work with me :
// ----------------------------------------------
//textBox2.Text = Environment.NewLine;
//textBox28.Text = textBox28.Text + Environment.NewLine;
//textBox2.Text = textBox28.Text + Environment.NewLine;
}
con.Close();
使用字符串“新行字符”'.\n“创建新行。像这样:
textBox1.Text = reader["Name"].ToString() + "\n";
textBox20.Text = reader["Description"].ToString() + "\n";
试试这个
textBox1.Multiline = true;
textBox1.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox1.AcceptsReturn = true;
textBox1.WordWrap = true;
textBox20.Multiline = true;
textBox20.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox20.AcceptsReturn = true;
textBox20.WordWrap = true;
while (reader.Read())
{
textBox1.Text += reader["Name"].ToString() + Environment.NewLine;
textBox20.Text += reader["Description"].ToString() + Environment.NewLine;
}
谢谢兄弟,但它的号码是一样的07704425588 0770258,但它显示像077044255880770258