Search code examples
c#mysqlstringmysqldatareader

C# get exact string from Mysql not working


I have problems with a MySQL data using C#. The string data in the database is a multiline text, I mean, with the " \n ". So I want to show it in a multiline texbox but it shows me everything in one line.

For example: the string in the database is: PICTURE OF THE DATABASE

"1

2"

But at the time of getting the data with the datareader and display it in a textbox in C # shows me: PICTURE OF THE PROGRAM

"1 2"

So how can i display it in separate lines? i mean, using the same format as in the database.


Solution

  • \r\n is the proper line ending for windows, so try replacing \n with \r\n and see if the output displays correctly.

    var test= mystring.Replace("\n", "\r\n");
    mytextbox.Text = test;
    

    Difference between \n and \r?