Insert carriage return/line feed with C# and ADO.NET

  • Thread starter Torsten Zachert
  • Start date
T

Torsten Zachert

I would like to insert some text with embedded carriage return/line feed
into a MS Access text field with OleDb and C# ADO.NET. I tried to use "\n"
in combination with "\r". If I display the input in a text field I only see
quads.

Tia

Torsten
 
D

Dirk Goldgar

Torsten Zachert said:
I would like to insert some text with embedded carriage return/line
feed into a MS Access text field with OleDb and C# ADO.NET. I tried
to use "\n" in combination with "\r". If I display the input in a
text field I only see quads.

What do you mean by "quads"? I'm not familiar with C#, but I know C, so
if you post your code I may be able to dope it out. How are you
checking your results? If you're looking in a table datasheet, you may
not see a second line in the field unless you enter the cell and use the
arrow or End key. If you're looking in a text box on a form, make sure
the text box is tall enough to show multiple lines.
 
T

Torsten Zachert

Dirk Goldgar said:
What do you mean by "quads"? I'm not familiar with C#, but I know C, so
if you post your code I may be able to dope it out. How are you
checking your results? If you're looking in a table datasheet, you may
not see a second line in the field unless you enter the cell and use the
arrow or End key. If you're looking in a text box on a form, make sure
the text box is tall enough to show multiple lines.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
Hi Dirk,

yes I have a multiline text box, but instead of the CRLF I see quadrats (non
visible character) between two words, where I inserted for instance "\n".

The code in nothing special:

string insertString = "thisString\n\r";
string query = string.Format("UPDATE tableXYZ SET textfield='{0}' WHERE
id=0", insertString);
oleDb1.ExecuteOleDbQuery(query, conn);

T.
 
D

Dirk Goldgar

Torsten Zachert said:
yes I have a multiline text box, but instead of the CRLF I see
quadrats (non visible character) between two words, where I inserted
for instance "\n".

The code in nothing special:

string insertString = "thisString\n\r";
string query = string.Format("UPDATE tableXYZ SET textfield='{0}'
WHERE id=0", insertString);
oleDb1.ExecuteOleDbQuery(query, conn);

Access recognizes CR+LF as a new-line, but not LF+CR. Try reversing the
order of the escape sequences:

string insertString = "thisString\r\n";
 
T

Torsten Zachert

I would like to insert some text with embedded carriage return/line feed
into a MS Access text field with OleDb and C# ADO.NET. I tried to use "\n"
in combination with "\r". If I display the input in a text field I only see
quads.
These 3 variants ar possible:

1.) Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString()

2.) "\r\n"

3.) Environment.NewLine

I think the last one is the best one.
 
D

Dirk Goldgar

Torsten Zachert said:
These 3 variants ar possible:

1.) Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString()

2.) "\r\n"

3.) Environment.NewLine

I think the last one is the best one.

Do I take it that they all work? Not knowing C#, I could only guess at
the second one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top