Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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