Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now