Solved

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

Posted on 2010-11-09
4
1,190 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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