I just try to read data from database line by line inside list box. Here is my each column section that "reader.GetString" represents - Username, Name, Surname, Department, Faculty etc.. I want them all to appear line by line for every row not side by side with "+=" for example;:
Steve_J
Steve Jackson
Romance-Germanic Department
German language and Literature
and the output of currently written code blocks (all in the same line with spaces between each column) is :
Steve_J Steve Jackson Romance-Germanic faculty Department of German language and Literature
David_21 David Ratchford Faculty of Archaeology Department of Scientific Archeology
How to go about that since we know list box doesn't take "\n"?
Source Code:
private void button2_Click(object sender, EventArgs e)
{
using (SqlConnection connect = new SqlConnection())
{
connect.ConnectionString = @"Data Source=DESKTOP-9I0BNAS\SQLEXPRESS;Initial Catalog=CAVID;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
connect.Open();
using (SqlCommand command = new SqlCommand("select * from Istifadeciler", connect))
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string data = reader.GetString(0)+ " ";
data += reader.GetString(1) + " ";
data += reader.GetString(2) + " ";
data += reader.GetString(3) + " ";
data += reader.GetString(4)+ " ";
data += reader.GetString(5) + " ";
data += reader.GetInt32(6).ToString()+ " ";
data += reader.GetInt32(7).ToString()+ " ";
listBox1.Items.Add(data);
}
}
}