KingBee KingBee - 1 year ago 78
C# Question

How do assign a value(string) from database to textbox

My issue is im trying to write a lambda expression! Problem is that I am not sure I am doing it right.

var result = dataset.student.Where(n => n.ID == num);
**num is a value recieved from id text box

var result stores my object pulled from database (which is a person), so now i need to assign the textbox "FirstNameTxtBox" with result FirstName

this.FirstNameTextBox = result.Where(n=>n.FirstName);

this is where I am failing as my expression keeps out "cannot convert String to bool. To be honest not sure if it is the right expression.
Hope this is clear.

Answer Source

It should be:

this.FirstNameTextBox.Text = result.Select(n => n.FirstName).FirstOrDefault();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download