Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I cant fix this exception, can someone help me with this.
Heres the code:
DataTable dt = new DataTable();

    dt.Columns.Add("Marker", typeof(string));
    dt.Columns.Add("Desc", typeof(string));
    dt.Columns.Add("Page", typeof(string));


    dt.Rows.Add("A1", "Desc1", "1");
    dt.Rows.Add("A2", "Desc2", "2");
    dt.Rows.Add("A3", "Desc3", "3");
    dt.Rows.Add("A4", "Desc4", "4");

    byte[] data = (byte[])dt.Rows[0][0];

    richTextBox1.Rtf = System.Text.Encoding.Unicode.GetString(data);


Thanks in advance;
Posted

The last 2 lines

MIDL
byte[] data = (byte[])dt.Rows[0][0];
richTextBox1.Rtf = System.Text.Encoding.Unicode.GetString(data);


Should be

richTextBox1.Rtf = dt.Rows[0][0].ToString();


There is no need to try to convert the string to a byte array and back to a string.
 
Share this answer
 
try this
byte[] data = System.Text.Encoding.Unicode.GetBytes(dt.Rows[0][0].ToString ());

instead of
byte[] data = (byte[])dt.Rows[0][0];
 
Share this answer
 
Comments
Rajesh Anuhya 9-Nov-10 2:36am    
Consider below answer also by David Ewen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900