String formatting using LINQ2SQL [closed]
I have a TextBox (which shows notes). Now the user Selects his/her name and then ADD the note. I want to show that note in the RIGHT Hand side of that page so that they can review his/her and past notes. My Table contains these items:
Memo
DateCreated User
This code here:
var showMemo = from r in em.EntityMemoVs_1s
where r.EntityID == getEntity
select r.Memo;
var showUser = from r in em.EntityMemoVs_1s
where r.EntityID == getEntity
select r.User;
tbShowNote.Text = String.Join(Environment.NewLine, showMemo);
tbShowNote.Text += String.Join(Environment.NewLine, showUser);
This is showing me notes in this fashion:
Test1 Test2 Test3 User1 User2 User3
I dont want this way...I want something like this:
5/5/2011: This is first note. -User1
5/6/2011: This is second note. -User2
How should I achieve this? Thanks!
Well, if you want everything inline, you could do:
var notes = from r in em.EntityMemoVs_1s
where r.EntityID == getEntity
select r.CreatedDate.ToShortDateString() + ": " +
r.Memo + " - " + r.User;
txtShowNote.Text = String.Join("<br/>", notes);
Essentially, create the string in the LINQ query as one statement, and if you are posting to the web, use <br/>
instead of New lines.
HTH.
精彩评论