When learning to work with an MS SQL Server database, when trying to output data from the ID , Name , Points columns of the users table, the program for some reason outputs the data of the Points line with a large indent as shown in the figure:

Screen console application

Please explain to me why there is such a situation, and how to solve this problem.
Method code:

 static void print() { DataClassesUserInfoDataContext Userinfo = new DataClassesUserInfoDataContext(); var custs = from c in Userinfo.users select new { Id = c.ID, Name = c.Name, Points = c.Points }; Console.WriteLine("ID - Name - Points"); foreach (var cust in custs) { Console.WriteLine("{0} - {1} - {2}", cust.Id, cust.Name, cust.Points); } Console.WriteLine("Нажмите любую клавишу для завершения работы..."); Console.ReadKey(); Environment.Exit(0); } 
  • Console.WriteLine("[{0}] - [{1}] - [{2}]", cust.Id, cust.Name, cust.Points); - Igor
  • @Igor imgur.com/s1LvgP1 - Andrey Pilip

1 answer 1

Because the values ​​in the Name field end in tails of spaces.

 Console.WriteLine("[{0}] - [{1}] - [{2}]", cust.Id, cust.Name, cust.Points); 

Probably, the field type in the database is a string, fixed length.

 Console.WriteLine("{0} - {1} - {2}", cust.Id, cust.Name.Trim(), cust.Points); 
  • I thank for the help in solving the problem, but I still do not understand how to arrange the unfixed length for the rows in the column Here is the screen of the database: imgur.com/197VQws - Andrey Pilip
  • 3
    @AndreyPilip varchar(50) - Igor