Not sending greek characters from asp.net page to SQL server

Hello experts,

I have a dual language web site (english and greek) and the web pages can view the greek characters fine, but it seems when i take a greek word or letters from a textbox and send that as an insert into a new record in my MSSQL database it loses the greek characters and comes out with ???!? for example.

However, i have set the table to read greek characters collation and when i manually input greek characters into it, it reads that fine and outputs onto a web page fine.

I understand that it is posting the this through a form, so obvioulsy the form is losing the greek charcters. Is there any way i can fix this?
thomasmuttonAsked:
Who is Participating?
 
Jai STech ArchCommented:
is it possible for you to check wht is the character that you are really inserting to SQL ? i mean keep a breakpoint at the poitn wehre the GREEK character goes to the DB...and check what is it inserting as

are you using INSERT statements ? if yes then you ahve to specify you query as
insert into tablename values(N'any greek character') mind the N it is to say that it is unicode...
0
 
thomasmuttonAuthor Commented:
StringBuilder CommandText = new StringBuilder();

        CommandText.Append("INSERT INTO ");
        CommandText.Append("tbl_HealthyLiving (");
        CommandText.Append("HealthyLiving_Name_en, ");
        CommandText.Append("HealthyLiving_Description_en, ");
        CommandText.Append("HealthyLiving_Image_en, ");
        CommandText.Append("HealthyLiving_Name_el, ");
        CommandText.Append("HealthyLiving_Description_el, ");
        CommandText.Append("HealthyLiving_Image_el, ");
        CommandText.Append("HealthyLiving_SavedDate) ");
        CommandText.Append(" VALUES (");
        CommandText.Append("'" + txtAddName_en.Text + "', ");
        CommandText.Append("'" + txtAddDesc_en.Text + "', ");
        CommandText.Append("'" + ddlAddImages.SelectedItem.Value + "', ");
        CommandText.Append("'" + txtAddName_el.Text + "', ");
        CommandText.Append("'" + txtAddDesc_el.Text + "', ");
        CommandText.Append("'" + ddlAddImages.SelectedItem.Value + "', ");
        CommandText.Append("'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')");

        SqlConnection myConnection = new SqlConnection(ConnectionString);
        SqlCommand myCommand = new SqlCommand(CommandText.ToString(), myConnection);

        myConnection.Open();
        myCommand.ExecuteNonQuery();
        myConnection.Close();

so with that code, you would suggest putting an 'N' before the actual line for example.

CommandText.Append(" N' " + txtAddName_el.Text + " ', ");

I am inserting 'ÅÀ¿´¿Ç®' and it is showing in the database as jibberish but the dataase isnt the problem i think. I think the problem lies with the posting of the information. eg Form
0
 
thomasmuttonAuthor Commented:
oh sorry about the last post, i tied to post a greek word but even experts exchange cannot understand it...
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
thomasmuttonAuthor Commented:
o.k i just did a reponse write on the query and this came up

INSERT INTO tbl_HealthyLiving (HealthyLiving_Name_en, HealthyLiving_Description_en, HealthyLiving_Image_en, HealthyLiving_Name_el, HealthyLiving_Description_el, HealthyLiving_Image_el, HealthyLiving_SavedDate) VALUES ('sdf', 'fdfdfd', 'BmiCalculator.jpg', 'ýýýýýýý', 'ýýýýýýý', 'BmiCalculator.jpg', '2007-10-19 14:20:36')

btw my charset is <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" /> which i do believe it for greek.
0
 
azza_cCommented:
Thomas,

Do you have an example of how you are inserting the text into the database?

Possible Unicode issue?

You may have to convert the string to Unicode before passing it into the insert statement or if being inserted as a parameter ensure that the parameter datatype is prefixed by n (ie: nvarchar).
0
 
Jai STech ArchCommented:
he has given the example...and nvarchar is already suggested pls read the full thread...
0
 
Jai STech ArchCommented:
thomas...check this probably will help you a lot
http://forums.asp.net/p/1099470/1678076.aspx
0
 
azza_cCommented:
Oh - sorry bout that - looks like it was posted whilst I was writing my comment
0
 
thomasmuttonAuthor Commented:
I have read that but i still dont understand. do i need to convert the string to nvarchar in asp.net?
0
 
azza_cCommented:
Maybe convert the txtAddName_el.Text from ascii to unicode. Code example --> http://gaaton.blogspot.com/2007/04/convert-ascii-to-unicode-in-c.html then pass it in with the N prefix
0
 
thomasmuttonAuthor Commented:
excuse me for being stupid but how would i do that with this code?

        Encoding ascii = Encoding.UTF32;

        char c = (char)asciiCode;
        Byte[] b = ascii.GetBytes(c.ToString());

i dont fully understand the above code and how i would convert the textbox etc
0
 
azza_cCommented:
Crap -  my bad - sorry - you are not being stupid - I am - not the best example of code and didn't really look at it properly before posting the comment. Disregard that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.