Solved

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

Posted on 2010-11-09
4
1,170 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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
BurnieP earned 250 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 250 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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