Hi vrindavani,
Check the below example.
You need to make the column type as NVARCHAR.
So that you can insert Hindi characters.
SQL
CREATE TABLE [dbo].[HindiNames]
(
[ID] INT IDENTITY PRIMARY KEY,
[Name] [VARCHAR](100) NULL,
[HindiName] [NVARCHAR](100) NULL
)
HTML
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Name</td>
<td><asp:TextBox ID="txtName" runat="server" /></td>
</tr>
<tr>
<td>Hindi Name</td>
<td><asp:TextBox ID="txtHindiName" runat="server" /></td>
</tr>
</table>
<br />
<asp:Button Text="Save" OnClick="Save" runat="server" />
<br />
<asp:Label ID="lblName" runat="server" />
:
<asp:Label ID="lblHindiName" runat="server" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Save(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string sqlStatment = "INSERT INTO [HindiNames] VALUES(@Name,@HindiName)";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
cmd.Parameters.AddWithValue("@Name", this.txtName.Text.Trim());
cmd.Parameters.AddWithValue("@HindiName", this.txtHindiName.Text.Trim());
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindData();
}
private void BindData()
{
string constr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string sqlStatment = "SELECT * FROM [HindiNames] ORDER BY ID DESC";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
lblName.Text = sdr["Name"].ToString();
lblHindiName.Text = sdr["HindiName"].ToString();
}
con.Close();
}
}
}
VB.Net
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim sqlStatment As String = "INSERT INTO [HindiNames] VALUES(@Name,@HindiName)"
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand(sqlStatment, con)
con.Open()
cmd.Parameters.AddWithValue("@Name", Me.txtName.Text.Trim())
cmd.Parameters.AddWithValue("@HindiName", Me.txtHindiName.Text.Trim())
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Me.BindData()
End Sub
Private Sub BindData()
Dim constr As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim sqlStatment As String = "SELECT * FROM [HindiNames] ORDER BY ID DESC"
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand(sqlStatment, con)
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
If sdr.Read() Then
lblName.Text = sdr("Name").ToString()
lblHindiName.Text = sdr("HindiName").ToString()
End If
con.Close()
End Using
End Using
End Sub
Screenshot