You have to show us what code you have in order for us to see where it is going wrong.
Reverend Jim
Illigitimae non carborundum
3,737 posts since Aug 2010
Reputation Points: 585
Solved Threads: 469
Skill Endorsements: 33
Since I'm Not a db.coder, I do not know of any other way to pursue this other than:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
With TextBox1 : .Text = replaceNewLine(.Text, True) : End With '// replace line.break w/String.
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
With TextBox1 : .Text = replaceNewLine(.Text, False) : End With '// replace String with line.break.
End Sub
Private Function replaceNewLine(ByVal selContent As String, ByVal isReplacingNewLineWithChar As Boolean, _
Optional ByVal selNewLineStringToUse As String = ".:.myCooLvbNewLine.:.") As String
If isReplacingNewLineWithChar Then : Return selContent.Replace(vbNewLine, selNewLineStringToUse)
Else : Return selContent.Replace(selNewLineStringToUse, vbNewLine)
End If
End Function
End Class
Basically, replace each line.break w/a char. or a string that will not be found or likely used in your db.items, save to db and un.replace?:D the line.break string when loading items from the db.
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
As previously mentioned, not a db.coder here, thus I'll edit w/no radar(my vb.net):D.
Dim sCoolNewLine As String = "~"
con.Open()
cmd = New SqlCommand("INSERT INTO SampleTbl VALUES('" & TextBox1.Text.Replace(vbNewLine, sCoolNewLine) & "'", con)
cmd.ExecuteNonQuery()
con.Close()
This TextBox1.Text.Replace(vbNewLine, sCoolNewLine) will replace line.breaks from a TextBox, w/a char("~") and should be done when updating your db(database).
To undo this, when retrieving info from db, reverse the .Replace process to TextBox1.Text.Replace(sCoolNewLine, vbNewLine) and you should get your line.breaks as previously were, in TextBox.
The char ("~") should be blocked from being typed by a user, to not confuse the way your code updates/retrieves data to/from db.
I used a String in my previously posted code, though you can always use just a char as "~" or "^", or even ".etc.". Reason for String; Not likely it will ever be typed by a user as ".:.myCooLvbNewLine.:." , thus no issues.
Hope this helps.:)
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
Don't use hard-coded SQL string and no-need to add/replace NewLine characters in text which is input via Multi-line textbox.
>@kenth21v : So if I retrieve the data it displays a single lined text.
May be you are trying to display text in Single line textbox. Try using Label or Multilie text.
Code to insert row.
Using Cn As New SqlConnection("your_connection_string")
Dim Sql = "insert into TestTable values (@mtext)"
Using Cmd As New SqlCommand(Sql, Cn)
Cmd.Parameters.Add("@mtext", SqlDbType.VarChar, 1000).Value = TextBox1.Text
Cn.Open()
Cmd.ExecuteNonQuery()
Cn.Close()
End Using
End Using
__avd
Posting Genius (adatapost)
8,737 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 51
Question Answered as of 1 Year Ago by
codeorder,
__avd
and
Reverend Jim