1

I have an aspx page with a textbox and button. When I clicked button, it's sending textbox's text to a function and saves it to database using entity framework. The issue is when I use my local characters in textbox such as ş, ğ, ı, ö , ü, these characters are saved as s, g, i, o, u. What is the problem?

My codes (Product.aspx)

 <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox> 
 <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />

(Product.aspx.cs)

 protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Product p = new Product ()
        {
            Id = Int32.Parse(Session["ProductId"].ToString()),
            Title = txtTitle.Text
        };
        int productId = ProductManager.UpdateProduct (p);
        if (productId != -1)
        {
            // SUCCESS
        }
        else
        {
             // ERROR
        }
    }


  public static int UpdateProduct(Product product)
    {
        using (var context = new LidyaEntities())
        {
            Product pUpd = context.Product.FirstOrDefault(p => p.Id == product.Id);
            if (pUpd != null)
            {
                pUpd.Title = product.Title;
            }
            return context.SaveChanges();
        }
    }

Database table (SQL SERVER);

  (Id, int)
  (Title, text)
1

2 Answers 2

2

Use "N" to solve this issue..

If you want to insert a string like "ҤїАͻ" into Database

Then your Query must be like this

Query:

INSERT INTO TableName VALUES (N'ҤїАͻ')

I think it will solve your problem

Sign up to request clarification or add additional context in comments.

7 Comments

But I dont call a query. I'm using entity-framework's add method.
@MehmetInce: what is the Data Type you are using to Save this words..?
I'am saving as 'text' type.
@MehmetInce: An nvarchar column can store any Unicode data but Varchar store only non Unicode . So changing from Text to NVarchar get Works..
@MehmetInce I have the same problem, My Column is already nVarchar, still can't save other languages to DB. Help?
|
1

Start by checking the database and confirm the value is stored properly. If it's not you will need to change the character type set of the string column. But before you do that confirm the text value in the code behind is correct too.

1 Comment

In database, my string is stored also without special characters. For example it's stored as 'cag'. Not 'çağ'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.