0

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();
}
2
  • how your data looks like? maybe you want to split it? Commented Nov 7, 2016 at 8:19
  • 1
    you can separate lines by adding "\r\n" or Environment.NewLine. On a side note, you must have a look to Parameterized Query Commented Nov 7, 2016 at 8:24

2 Answers 2

1
textBox1.Multiline = true;

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

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

Please don't use SELECT *, you can use SELECT Col1, Col2...

Also please use parameterized queries to avoid SQL injection.

Please us using with the SQL connection

Sign up to request clarification or add additional context in comments.

2 Comments

its same bro same error show data all in one line ex 07701442233 07705552233
all my data is string
0

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
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.