Wednesday, 6 July 2016

How to save hindi font in MS-Sql Server with Google Api

How to save hindi font in MS-Sql Server with Google Api
 गूगल पी आइ की सहायता डेटाबेस में  हिंदी फॉन्ट कैसे सेव करे

-- Sql Query---------------

create database test
use test
create  table Student_Info
(
RollNo int primary key,
Name nvarchar(50),
StudentInfo nvarchar(50)
)

Note : Column datatype  must be nvarchar type…..

Code for  Default.aspx page……………………………………

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
height: 23px;
}
</style>

<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript">

// Load the Google Transliterate API
google.load("elements", "1", {
packages: "transliteration"
});

function onLoad() {
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.HINDI],
transliterationEnabled: true
};

// Create an instance on TransliterationControl with the required
// options.
var control =
new google.elements.transliteration.TransliterationControl(options);

// Enable transliteration in the textbox with id
// 'transliterateTextarea'.
control.makeTransliteratable(['txtname']);
control.makeTransliteratable(['txtinfo']);
}
google.setOnLoadCallback(onLoad);
</script>

</head>
<body>
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td colspan="2">How to save hindi font in MS-Sql Server
<b> डेटाबेस में  हिंदी फॉन्ट कैसे सेव करे </b>
</td>

</tr>
<tr>
<td>RollNo  रोल नंबर</td>
<td>
<asp:TextBox ID="txtrollno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> Name (नाम )</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Student Details(स्टूडेंट विवरण) </td>
<td>
<asp:TextBox ID="txtinfo" runat="server" Height="51px" Width="179px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<asp:Button ID="btnsave" runat="server" OnClick="Button1_Click" Text="Save" />
<asp:Label ID="lblmessage" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style2" colspan="2">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<div>

</div>
</form>
</body>
</html>

Code for  Default.aspx.cs  page……………………………………

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

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowData();
}

}
SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=test;User ID=sa;Password=123");
protected void Button1_Click(object sender, EventArgs e)
{
//string[] lines = Regex.Split(txtinfo.Text, "\r\n");

SqlCommand cmd = new SqlCommand("insert into Student_Info values(@RollNo,@Name,@UserInfo)", con);
cmd.Parameters.AddWithValue("RollNo", Convert.ToInt32(txtrollno.Text));
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@UserInfo", txtinfo.Text);
if (con.State.ToString() != "Open")
{
con.Open();
}
cmd.ExecuteNonQuery();
con.Close();
lblmessage.Visible = true;
lblmessage.ForeColor = Color.Red;
lblmessage.Text = "Data Saved Successfully";
ShowData();


}

private void ShowData()
{
SqlCommand cmd = new SqlCommand("select * from Student_Info", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

}
}


Result

0 comments:

Post a Comment