Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to add carriage return (vbCr) in SQL Table and read it back (Web Application)

Posted on 2010-11-09
4
Medium Priority
?
1,199 Views
Last Modified: 2013-11-05
I didn't know how properly title the question.

TASK:
READ THE mainframe file, load the content into SQL Server table  field (varchar(MAX) data type) display the saved content in text box (multiline) now coming from SQL.

APPLICATION/LANGUAGE:
WEB APPLICATION - VB.NET

I'm reading the mainframe file (sits on shared directory) with 15-20 lines that looks like this.
//BLABLA  FILE (092128000),'SAMPLE',                                    
 //             NOTIFY=WHATEVER,                                                   
 //             BLABLALBA                                
 //****************************************************************              
 //********************    BLABLA  *********************              
 //****************************************************************              
 //************    JCL GENERATED AT 09:25 ON BLABLA ***********              
 //****************************************************************              
 //*      BLA BLA 
 //****************************************************************              
 //***                                                                           
 //******                                                                        
 //****************************************************************              
 // etc..

Open in new window


Ok, so the file that looks like .txt comes with carriage returns already. If I read  the file and display on the web form (multiline textbox) right away - it's fine.

NOW, if I save the file content into sql table it saves with no carriage returns
 While (InlineAssignHelper(line, fileReader.ReadLine())) IsNot Nothing
                            'from here the second line is reading
                            sb.AppendLine(line)
 End While

Open in new window

so when I read it back and display on web form textbox (multiline) it looks like this:
All lines are displayed... just ignore not complete example. but it looks like not formatted with no carriage returns.
//BLABLA  FILE (092128000),'SAMPLE',     //      //  NOTIFY=WHATEVER, ,    //      1,1) 

Open in new window


MY APPROACH:
I added "vbCr" to end of each line.
 
Dim input As New FileStream(filename, FileMode.Open, FileAccess.Read)
fileReader = New StreamReader(input)
BtnSave.Enabled = False
lblWhatever.Text = Path.GetFileNameWithoutExtension(filename)

  Dim sb As New StringBuilder()
   Dim line As String = String.Empty
           While (InlineAssignHelper(line, fileReader.ReadLine())) IsNot Nothing
                sb.Append(line & "vbCr")
            End While

    Dim finalResult As String = sb.ToString()
  txtFileContent.Text = finalResult 

Open in new window


I'm taking  the 'finalResult' string value and that's how I insert the records into database so it looks like this:
BLA BLA,           vbCr//             //*******************************      vbCr//

Open in new window

 
Then my code reads it back and replaces "vbCr" string with actual vbCR
Dim Code As String = MyObject.FileContent
txtWhatever.Text = Code.Replace("vbCr", vbCr)

Open in new window


         
NOW QUESTION/ISSUE:

 
Boss doesn't want to see vbCr string in Sql field. ANY SUGGESTION?
0
Comment
Question by:smano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 1000 total points
ID: 34098369
Can you replace the carriage return by char(13) + char(10) before inserting it in the database?
If you save it with char(13) + char(10), it should be the same as vbCr.
0
 
LVL 21

Assisted Solution

by:Alfred1
Alfred1 earned 1000 total points
ID: 34098449
Using a VARCHAR(MAX) should be able to accept carriage return and line feed without any problems.  

Since you are using VB, why don't you just use the constant vbCrLf to append in your line?  That should do the trick.  See the code below.  I changed your "vbCr" string into vbCrLf.
Dim input As New FileStream(filename, FileMode.Open, FileAccess.Read)
fileReader = New StreamReader(input)
BtnSave.Enabled = False
lblWhatever.Text = Path.GetFileNameWithoutExtension(filename)

  Dim sb As New StringBuilder()
   Dim line As String = String.Empty
           While (InlineAssignHelper(line, fileReader.ReadLine())) IsNot Nothing
                sb.Append(line & vbCrlf)
            End While

    Dim finalResult As String = sb.ToString()
  txtFileContent.Text = finalResult 

Open in new window

0
 
LVL 1

Author Comment

by:smano
ID: 34099196
I'll try tomorrow at work.
The issue I'm having once again is that when I read the previously inserted file content back from database it doesn't show up with carriage return once I display it in the textbox (multiline mode)
0
 
LVL 1

Author Comment

by:smano
ID: 34104868
I figured what the issue was ... kind of silly.
If I take the "finalResult" string value as Copy Value and manually insert into SQL table I DO NOT get carriage returns. I did it manually for testing reason.

If I programmatically insert the "finalResult" into SQL table I DO. Duh...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question