开发者

String formatting using LINQ2SQL [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not 开发者_高级运维generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜