Thursday, January 9, 2014

Save data in SqlServer database in any language (hindi, english,Odia, marathi, etc) using Asp.Net (C#).

Here I am going to explain ,How can you Save data in SqlServer database in any language (hindi,  english,Odia, marathi, etc) using Asp.Net (C#).
Here I am using Google API to Convert English language to other language.
Previously I Explain How to  Convert English Language to Other Language Using Google API.

Very Easy way to store any Language data in SqlServer DataBase and Display in GridView.

Download Code Here

Demo :



Step 1 : Create a Table like Below Image.
         
Give the Table Name "Language" and save.

Step 2 : Now Create a Website and Copy and Paste the JavaScript Before </head>
   (In <Head> Section).

<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, Hindi ,Odia, Marathi, Malayalam etc.
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
        };

        var control = new google.elements.transliteration.TransliterationControl(options);
        control.makeTransliteratable(['txtconvert']);
    }
    google.setOnLoadCallback(onLoad);

</script>

Step 3:
Explanation :
 Copy and Paste the full  below code in .aspx page 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <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(['txtconvert']);
    }
    google.setOnLoadCallback(onLoad);

</script>

<style type="text/css">

.btnsaroj{
border:1px solid #25729a; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 10px 10px 10px 10px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
 background-color: #3093c7; background-image: linear-gradient(to bottom, #3093c7, #1c5a85);
 }

.btnsaroj:hover{
 border:1px solid #1c5675;
 background-color: #26759e; background-image: linear-gradient(to bottom, #26759e, #133d5b);
 }
    .style1
    {
        color: rgb(255, 0, 0);
    }
</style>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <pre class="code" 
     
            style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: white; border: 6px solid rgb(234, 234, 234); color: rgb(68, 68, 68); font-family: 'courier new'; font-size: 13px; line-height: 18px; outline: rgb(212, 212, 212) solid 1px; overflow: auto; padding: 15px; position: relative; width: 760px; top: 0px; left: 0px; height: 726px;">
<asp:Image ID="Image1" runat="server" Height="79px" ImageUrl="~/dotnetlogo.png" 
            Width="246px" />



Enter Text :<asp:TextBox ID="txtconvert" runat="server" ClientIDMode="Static" 
            Height="36px" placeholder="Welcome To Easy Dot Net Coding" TextMode="MultiLine" 
            Width="328px"></asp:TextBox>

<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" CssClass="btnsaroj" />                <asp:Button 
            ID="Button1" runat="server" onclick="Button1_Click" Text="Display" CssClass="btnsaroj" />      
       
 <span class="style1"> Here you can save any Language Data
in DataBase and also Display the Data
in GridView control(Use any control).
(Language Like Hindi,Odia,English etc.)</span>
  <asp:Label ID="lblMessage" runat="server" 
            style="font-weight: 700; color: #FF0000" />                                                      
                                                     
<asp:GridView ID="gvdata" runat="server" AutoGenerateColumns="False" 
            BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
            CellPadding="3" Height="179px" Width="293px"><Columns><asp:BoundField DataField="id" 
                     HeaderText="Id" /><asp:BoundField DataField="langu" HeaderText="Content" /></Columns><FooterStyle 
                 BackColor="White" ForeColor="#000066" /><HeaderStyle BackColor="#006699" 
                 Font-Bold="True" ForeColor="White" /><PagerStyle 
                 ForeColor="#000066" HorizontalAlign="Left" BackColor="White" /><RowStyle 
                 ForeColor="#000066" /><SelectedRowStyle BackColor="#669999" 
                 Font-Bold="True" ForeColor="White" /><SortedAscendingCellStyle 
                 BackColor="#F1F1F1" /><SortedAscendingHeaderStyle 
        BackColor="#007DBB" /><SortedDescendingCellStyle 
                 BackColor="#CAC9C9" /><SortedDescendingHeaderStyle 
        BackColor="#00547E" /></asp:GridView>
</pre>
    
    </div>
    </form>
</body>

</html>

Step 4:
Copy the Below Code and Paste in .aspx .CS page

NameSpace 

using System.Data;

using System.Data.SqlClient;

Then 

 SqlConnection con = new SqlConnection("Data Source=COMPUTER;Initial Catalog=Testing;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblMessage.Visible = false;
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtconvert.Text != "")
        {
            con.Open();
            SqlDataAdapter adp = new SqlDataAdapter("insert into language  values (N'" + txtconvert.Text + "')", con);
            DataSet ds = new DataSet();
            lblMessage.Text = txtconvert.Text;
            adp.Fill(ds);
            con.Close();
        }
        else
        {
            lblMessage.Text = "TextBox can not empty";
            lblMessage.Visible = true;
        }

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        SqlDataAdapter adp = new SqlDataAdapter("select * from  language ", con);
        DataSet ds = new DataSet();
        // lblMessage.Text = txtHindiContent.Text;
        lblMessage.Visible = false;
        adp.Fill(ds);
        gvdata.DataSource = ds;
        gvdata.DataBind();
        con.Close();
    }

}


If This Code Help You ,Please Share.


4 comments:

  1. not working.
    Should i download API before using it?

    ReplyDelete
    Replies
    1. No Need to download , just use google api in head tag.
      Download the full program and check it.

      Delete