Reputation: 304
Created a class to return columns from an SQL table [USER]. But when the data shows in the listbox it only shows the first two columns.
Class to return columns
public class User
{
public int USER_ID { get; set; }
public string Username { get; set; }
public string First_Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string FullInfo
{
get {
return $"{USER_ID} { Username } { First_Name } { Surname } { Email } ";
}
}
}
Calling the User class and populating the listbox
public partial class DashBoard : Form
{
List<User> user = new List<User>();
public DashBoard()
{
InitializeComponent();
UpdateBinding();
}
private void UpdateBinding()
{
UserFoundListBox.DataSource = user;
UserFoundListBox.DisplayMember = "FullInfo";
}
private void SearchButton_Click(object sender, EventArgs e)
{
DataAccess db = new DataAccess();
user = db.GetUser(LastNameText.Text);
UpdateBinding();
}
}
When I add a break point and go into user, I can see that the data returns correctly. But when I look into fullinfo I can only see USER_ID and USERNAME. When I look in the text visualiser for fullinfo I can see that all the columns are returned but with big spaces between.
Upvotes: 1
Views: 171
Reputation: 304
The datatypes in the fields of my database were nchar(250).
I deleted all data from the [USER] table and updated the fields to varchar(250) and then inserted data. This meant all the spaces were gone and all the data showed.
Upvotes: 2