?
Solved

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

Posted on 2007-10-19
12
Medium Priority
?
729 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:thomasmutton
  • 5
  • 4
  • 3
12 Comments
 
LVL 14

Accepted Solution

by:
Jai S earned 2000 total points
ID: 20108559
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
 

Author Comment

by:thomasmutton
ID: 20108583
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
 

Author Comment

by:thomasmutton
ID: 20108603
oh sorry about the last post, i tied to post a greek word but even experts exchange cannot understand it...
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

Author Comment

by:thomasmutton
ID: 20108644
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
 
LVL 1

Expert Comment

by:azza_c
ID: 20108657
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
 
LVL 14

Expert Comment

by:Jai S
ID: 20108667
he has given the example...and nvarchar is already suggested pls read the full thread...
0
 
LVL 14

Expert Comment

by:Jai S
ID: 20108671
thomas...check this probably will help you a lot
http://forums.asp.net/p/1099470/1678076.aspx
0
 
LVL 1

Expert Comment

by:azza_c
ID: 20108717
Oh - sorry bout that - looks like it was posted whilst I was writing my comment
0
 

Author Comment

by:thomasmutton
ID: 20108727
I have read that but i still dont understand. do i need to convert the string to nvarchar in asp.net?
0
 
LVL 1

Expert Comment

by:azza_c
ID: 20108860
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
 

Author Comment

by:thomasmutton
ID: 20108917
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
 
LVL 1

Expert Comment

by:azza_c
ID: 20108985
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question