locked
I want to save and retrieve data to sql in hindi language from asp.net webpage RRS feed

  • Question

  • User-1647172364 posted

    Hlo Professionals!

    Here is my code

    Html Code

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Test lang.aspx.cs" Inherits="WebApplication14.Test_lang" %>
    <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="body" runat="server">


    <div style="margin-top:30px; margin-left:20px">




    <h1><strong style="color:black">Test Language</strong></h1>
    <hr />

    <table>

    <tr>
    <td><span style="color:black">First Name</span><br />
    <asp:TextBox ID ="tb_name" runat="server" Width="200px" /><br />


    </td>

    <td><span style="margin-left:25px; color:black">Last Name<br /></span>
    <span style="margin-left:25px"><asp:TextBox ID="tb_last" runat="server" Width="200px" /></span> <br />

    </td>

    </tr>

    <tr>

    <td><br />
    <asp:Button ID="BT_submit" runat="server" Text="Submit" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_submit_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /></td>
    </tr>
    </table>
    </div>
    <div>
    <asp:GridView runat="server" AutoGenerateColumns="false" ID="Gv1" Width="100%" >
    <Columns>
    <asp:BoundField DataField ="first_name" HeaderText ="First Name" />
    <asp:BoundField DataField ="last_Name" HeaderText ="Last Name" />

    </Columns>

    <EditRowStyle BackColor="#2461BF" />

    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
    <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" />
    </asp:GridView>



    </div>



    </asp:Content>

    C# Code

    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 Test_lang : 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();
    }

    public void FillGridview()
    {
    SqlDataAdapter adp = new SqlDataAdapter("select * from test_hp", connection);
    adp.SelectCommand.CommandType = CommandType.Text;
    DataTable DT = new DataTable();
    adp.Fill(DT);

    Gv1.DataSource = DT;
    Gv1.DataBind();


    }

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)


    {

    }

    }


    protected void BT_submit_Click(object sender, EventArgs e)
    {
    EstablishConnection("sp_insert_test_hp");
    cmd.Parameters.Add("@first_name", SqlDbType.VarChar, 100).Value = tb_name.Text;
    cmd.Parameters.Add("@last_name", SqlDbType.VarChar, 100).Value = tb_last.Text;
    cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString();
    cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1";
    cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString();

    try { cmd.ExecuteNonQuery(); }


    catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); }
    CloseConnection();

    FillGridview();
    }


    }
    }

    Monday, June 8, 2020 9:11 AM

All replies

  • User288213138 posted

    Hi sanam13,

    I want to save and retrieve data to sql in hindi language from asp.net webpage

    Do you want to convert other languages to hindi? if so, you can try this demo:

    <table>
            <tr>
                <td>Type in Hindi : </td>
                <td>
                    <asp:TextBox ID="txtHindiContent" runat="server" ClientIDMode="Static" TextMode="MultiLine" Height="100" Width="250"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    </td>
                <td><asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <asp:Label ID="lblMessage" runat="server" />
                </td>
            </tr>
        </table>
        <div>
     
            <asp:GridView ID="gvContent" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField HeaderText="Sl No" DataField="SLID" />
                    <asp:BoundField HeaderText="Content" DataField="HindiContent" />
                </Columns>
            </asp:GridView>
        </div>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script type="text/javascript" src="https://www.google.com/jsapi?key=YourKeyHere">
        </script>
        <script language="javascript" type="text/javascript">
            google.load("elements", "1", {
                packages: "transliteration"
            });
     
            function onLoad() {
                var options = {
                    sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
                    destinationLanguage: google.elements.transliteration.LanguageCode.HINDI, // available option English, Bengali, Marathi, Malayalam etc.
                    shortcutKey: 'ctrl+g',
                    transliterationEnabled: true
                };
     
                var control = new google.elements.transliteration.TransliterationControl(options);
                control.makeTransliteratable(['txtHindiContent']);
            }
            google.setOnLoadCallback(onLoad);
     
        </script>
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    PopulateContent();
                }
            }
    
        private void PopulateContent()
            {
                using (MyDatabaseEntities dc = new MyDatabaseEntities())
                {
                    gvContent.DataSource = dc.ContentTables.ToList();
                    gvContent.DataBind();
                }
            }
    
    protected void btnSave_Click(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(txtHindiContent.Text.Trim()))
                {
                    using (MyDatabaseEntities dc = new MyDatabaseEntities())
                    {
                        dc.ContentTables.Add(new ContentTable
                        {
                             SLID = 0,
                             HindiContent= txtHindiContent.Text.Trim()
                        });
                        dc.SaveChanges();
                        lblMessage.Text = "Successfully saved!";
                    }
                    PopulateContent();
                }
            }

    More information about how to set the language you can refer to this video:

    https://www.youtube.com/watch?v=TV9U7Adoj_o

    Best regards,

    Sam

    Monday, June 8, 2020 10:04 AM