Reputation: 4179
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)
Upvotes: 1
Views: 1927
Reputation: 9126
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
Upvotes: 2
Reputation: 7591
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.
Upvotes: 1