locked
punjabi or hindi language data will not save in sql server 2012 it shows ?????? RRS feed

  • Question

  • User-1026236167 posted

    hello

    in my code there is remarks column in gridview and remarks column i used nvarchar(255)  when i put data in punjabi or hindi in textbox of remarks named there will be data saved in gridview and database shows ???? not real punjabi or hindi content

    so my requirement is how to save punjabi or hindi data in database

    i will use sql server 2012 there are number of collations of variours languages but not hindi or punjabi

    please execute them

    css

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;

    namespace WebApplication14
    {
    public partial class WebForm61 : System.Web.UI.Page
    {
    SqlCommand cmd = new SqlCommand();
    SqlConnection con = new SqlConnection();
    string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString();


    public void EstablishConnection(string storeprocedure)
    {
    con.ConnectionString = connection;
    cmd.Connection = con;
    cmd.Connection.Open();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = storeprocedure;
    }


    public void CloseConnection()
    {
    cmd.Connection.Close();
    cmd.Connection.Dispose();
    con.Close();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    FillGridview();
    Button3.Visible = false;
    }
    }

    public void FillGridview()
    {
    SqlDataAdapter adp = new SqlDataAdapter(" select * from tbl_package", connection);
    DataTable DT = new DataTable();
    adp.Fill(DT);
    GridView1.DataSource = DT;
    GridView1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    LinkButton btn = (LinkButton)sender;
    GridViewRow gvr = (GridViewRow)btn.NamingContainer;
    TextBox2.Text = gvr.Cells[0].Text;
    TextBox3.Text = gvr.Cells[1].Text;
    TextBox4.Text = gvr.Cells[2].Text;

    Button2.Visible = false;
    Button3.Visible = true;

    }


    protected void Button2_Click(object sender, EventArgs e)
    {
    EstablishConnection("sp_insert_package");
    cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 255).Value = TextBox2.Text;
    cmd.Parameters.Add("@reward", SqlDbType.VarChar, 255).Value = TextBox3.Text;
    cmd.Parameters.Add("@remarks", SqlDbType.NVarChar, 255).Value = TextBox4.Text;
    cmd.Parameters.Add("@by_whom", SqlDbType.VarChar, 255).Value = "1";
    cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 255).Value = System.DateTime.Now.ToString();
    cmd.Parameters.Add("@status", SqlDbType.VarChar, 255).Value = "1";

    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('Record Add Sucessfully');", true);
    try { cmd.ExecuteNonQuery(); }
    catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }

    FillGridview();

    con.Close();
    CloseConnection();
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
    EstablishConnection("sp_update_package");
    cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 255).Value = TextBox2.Text;
    cmd.Parameters.Add("@reward", SqlDbType.VarChar, 255).Value = TextBox3.Text;
    cmd.Parameters.Add("@remarks", SqlDbType.NVarChar, 255).Value = TextBox4.Text;
    cmd.Parameters.Add("@by_whom", SqlDbType.VarChar, 255).Value = "1";
    cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 255).Value = System.DateTime.Now.ToString();
    cmd.Parameters.Add("@status", SqlDbType.VarChar, 255).Value = "1";

    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('Record Add Sucessfully');", true);
    try { cmd.ExecuteNonQuery(); }
    catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }

    FillGridview();

    con.Close();
    CloseConnection();
    }

    }
    }

    aspx

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="WebForm61.aspx.cs" Inherits="WebApplication14.WebForm61" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="contentbody" runat="server">

    <div >
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

    <table>

    <tr>

    <td><span style="margin-left:20px">Package name</span><br />
    <span style="margin-left:20px"><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </span>
    </td>

    <td ><span style="margin-left:100px">Reward</span><br />
    <span style="margin-left:100px"><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </span>
    </td>

    <td><span style="margin-left:100px">Remarks</span><br />
    <span style="margin-left:100px"><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    </span>
    </td>
    </tr>

    </table>

    <br />

    <br />

    <asp:Button ID="Button2" runat="server" Text="Save" OnClick="Button2_Click" />
    <asp:button ID="Button3" runat="server" Text="update" OnClick="Button3_Click" />
    <br />
    <br />

    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="both"
    AutoGenerateColumns="False"
    DataKeyNames="tbl_id" Height="264px" Width="100%"
    BorderColor="#FF0066" >
    <AlternatingRowStyle BackColor="White" />
    <Columns>
    <asp:TemplateField>

    <ItemTemplate>
    <asp:LinkButton ID="Button1" runat="server" Width="25px" OnClick="Button1_Click">edit</asp:LinkButton>
    </ItemTemplate>

    </asp:TemplateField>
    <asp:BoundField DataField="package_name" HeaderText="Package name" />
    <asp:BoundField DataField="reward" HeaderText="Reward" />
    <asp:BoundField DataField="remarks" HeaderText="Remarks" />

    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
    <SelectedRowStyle BackColor="#FF66FF" />
    </asp:GridView>

    </ContentTemplate>
    </asp:UpdatePanel>

    </div>


    </asp:Content>

    Monday, June 8, 2020 11:28 AM

All replies

  • User-719153870 posted

    Hi prabhjot1313,

    SQL Server cannot recognize the hindi language so it shows ?????? instead. Use the letter N to prefix Unicode character string.

    Please check nchar and nvarchar:

    "Prefix a Unicode character string constants with the letter N to signal UCS-2 or UTF-16 input, depending on whether an SC collation is used or not. Without the N prefix, the string is converted to the default code page of the database that may not recognize certain characters. "

    Update your SP query like below:

    insert into #AAA values(N'हिन्दी')

    Best Regard,

    Yang Shen

    Tuesday, June 9, 2020 1:31 AM