Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2010
    Posts
    22

    Unanswered: CRLF - how to achieve this when inserting data from a web form

    Hi. We're working on a project that will read in input from a web form and insert that data into a table. The question/problem we anticipate having is, how do we deal with fields like Comments which could be quite lengthy and include paragraphs? How do we preserve the line breaks and carriage returns? Does SQL automatically detect these from the field and INSERT them properly?

    The behind code is basically going to say, "grab the content of TextBox3, INSERT that into field Comments of table Accounts." Is simply grabbing that content and INSERTing it going to be enough, or are we going to have to do something crazy like "read through the content of TextBox3, for every linebreak/carriage return append nchar(10) + nchar(19) to the INSERT query, resume reading through the content of TextBox3, repeat until end of TextBox3"?

    EDIT: the idea is so that later when we want to browse through the Comments in another web form, the query doesn't just output one long unformatted line in the web form, but rather in the exact format that it was typed in by the user when it was inserted.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The contents of a text control are the contents of the control. The formatting is determined by the control, not any code you write that uses the text control.

    What you get from the control depends on how your particular control formats the text data internally. Depending on how well your control is written and how it stores data, it might be properly formatted from the git-go. If the control is particularlly ill-behaved, the data might be spaghetti. This is controlled by the text control, not by anything you do with it.

    Give it a shot and try to just transfer the data and see how it works. If the text control is well behaved, then you'll be in good shape. If it isn't... Well, you'll have to figure out how to fix whatever they give you.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Define "formatting". HTML, Richtext, other?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Sep 2010
    Posts
    22
    Only thing I want to know is how to preserve those carriage returns and line breaks. Not concerned with other "formatting" like font.

    And thanks, Pat. Will give it a shot.

  5. #5
    Join Date
    Sep 2010
    Posts
    22
    Well, I went ahead and just tried it. I input a two paragraphs into a TextBox, UPDATE'd an SQL database with what was in that TextBox, and then SELECT'd that field and output it into another TextBox, only to find that the two paragraphs had just become one really long line.

    Based on what Pat said though, this looks like less of a database issue and more an issue with ASP.NET TextBox controls. Guess I'll go bother the ASP.NET folks on the asp.net forum Thanks for helping me narrow down the issue though!

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    No problem! I'm always glad to "stir the pot" and can often at least point you in the right general direction!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  7. #7
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    What I do is Use the Replace command

    displaytext = replace(datatext,vbnewline,"<br/>") on in html pages
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  8. #8
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    That "<br />" business is what we're talking about when we say formatting btw. If you're displaying stuff in an html based control (read: NOT richtext), then it's on you to "format" your message in html. That said, html does not speak linebreaks, it speaks <br />, <p />, etc.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  9. #9
    Join Date
    Sep 2010
    Posts
    22
    Thanks, everyone.

    I've played around with the database more before moving ahead with the web app, and have more exciting () questions on the topic of CRLF and SQL databases. Let's rewind and ignore the web/HTML part of things, and just talk about the database (I want to fully understand this before I half-assedly try and implement some web app that utilizes it).

    I'm using SQL Server Management Studio 2008 R2. I tried the following tests, and I have yet to figure out how to get a query result to keep the paragraphs intact; as it is now, every query just returns one long line.

    1) Typed two test paragraphs in Notepad. Using the Edit Top 1000 Rows of the Server Manager, I manually tried to copy/paste the contents of the Notepad into a column. No good. The paste ends at the CRLF, and the second paragraph isn't pasted at all. Fair enough, I didn't really expect this idea to work.

    2) Instead of using Edit Top 1000 Rows, I tried an INSERT query as follows:

    Code:
    INSERT INTO Accounts (GenInfo)
    VALUES ('test multiple paragraphs
    
    test multiple paragraphs2')
    Result of a SELECT query on this = all in one line. Meh, I can kind of understand why --- the query editor just ignores such white spaces and trims it automatically I guess?

    3) Another INSERT query as follows:

    Code:
    INSERT INTO Accounts (GenInfo)
    VALUES ('test multiple paragraphs' + char(13) + char(10) + 'testing multiple paragraph2')
    Result of a SELECT query on this also = all in one line. Now this I expected to work...

    ---

    I thought maybe it just "appears" as one line in the query result grid of Server Management Studio, so I copy/pasted the results into Notepad, Word, and so on, only to find that it copy/pastes exactly as it appears in the query result: all on one line.

  10. #10
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Re-run the statements using the Ctrl-T option to retrieve as text instead of as a grid. Be sure to protect your jaw when you run them.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  11. #11
    Join Date
    Sep 2010
    Posts
    22
    Hah, so simple. The biggest challenge with diving headfirst into programming is not understanding how to implement stuff, it's simply knowing what is possible/what kinds of functions these IDE's have/what methods and functions are already available. So often I bang my head against the keyboard wrestling with a problem trying to re-invent the wheel, and the solution was a measly Ctrl+T.

    Anyhow, problem solved! I'm sure I'll be back with another exciting thread next week, and I'm sure the solution will be another one-liner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •