Insert different languages Text characters in SQL Server using C# and VB.Net in ASP.Net

Last Reply on Feb 02, 2017 06:34 AM By AnandM

Posted on Feb 02, 2017 04:08 AM

i am fetching data from database.When i do data entry in any other language accept english it show me ??????????????? question mark instead of  name what should i do

Posted on Feb 02, 2017 06:34 AM

Hi jordan,

I have created a sample which full fill your requirement by taking reference of below article

Insert Hindi, Marathi, Gujarati, Urdu, Persian, Arabic, Tamil and Telugu languages Text characters in SQL Server using C# and VB.Net

HTML

<div>
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                Language:-
            </td>
            <td>
                <asp:TextBox ID="txtLanguage" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                Content:-
            </td>
            <td>
                <asp:TextBox ID="txtContent" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button1" Text="Save" runat="server" OnClick="Save" />
            </td>
            <td>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <br />
    <asp:GridView ID="GridView1" runat="server" EmptyDataText="There are no records"
        AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="Language" HeaderText="Language" />
            <asp:BoundField DataField="Content" HeaderText="Content" />
        </Columns>
    </asp:GridView>
</div>

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindGrid();
    }
}

protected void Save(object sender, EventArgs e)
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("INSERT INTO Languages VALUES(@Language, @Content)", con))
        {
            cmd.Parameters.AddWithValue("@Language", txtLanguage.Text);
            cmd.Parameters.AddWithValue("@Content", txtContent.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        BindGrid();
    }
}

public void BindGrid()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM Languages", con))
        {
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}

VB.Net

Protected Sub Page_Load(sender As Object, e As EventArgs)
	If Not IsPostBack Then
		BindGrid()
	End If
End Sub

Protected Sub Save(sender As Object, e As EventArgs)
	Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
	Using con As New SqlConnection(constr)
		Using cmd As New SqlCommand("INSERT INTO Languages VALUES(@Language, @Content)", con)
			cmd.Parameters.AddWithValue("@Language", txtLanguage.Text)
			cmd.Parameters.AddWithValue("@Content", txtContent.Text)
			con.Open()
			cmd.ExecuteNonQuery()
			con.Close()
		End Using
		BindGrid()
	End Using
End Sub

Public Sub BindGrid()
	Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
	Using con As New SqlConnection(constr)
		Using cmd As New SqlCommand("SELECT * FROM Languages", con)
			Dim sda As New SqlDataAdapter(cmd)
			Dim dt As New DataTable()
			sda.Fill(dt)
			GridView1.DataSource = dt
			GridView1.DataBind()
		End Using
	End Using
End Sub

ScreenShot