Answered by:
Russia Text insert into database and how to get

Question
-
User-444409258 posted
dear please solve my problem
how to insert Russia language text into database and how to get Russia text from database in asp.net using c sharp
please solve my problem
thanksMonday, December 5, 2011 2:47 AM
Answers
-
User-1312722619 posted
<meta name="Generator" content="Microsoft Word 12 (filtered medium)" />
Hi,<o:p></o:p>
<o:p> </o:p>
Please use following syntax in your INSERT and UPDATE commands. Try to add N for text parameters <o:p></o:p>
<o:p> </o:p>
str = string.Format("insert into Home (Cat, description, pos) values (N'" + home_Title.Text + "',N'" + Home_name.Text + "'," + pass + ")");<o:p></o:p>
<o:p> </o:p>
qry = string.Format("update Home set Cat = N'" + home_Title.Text + "', description= N'" + Home_name.Text + "' where Catid=" + id + "");<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 5, 2011 7:09 AM
All replies
-
User-821857111 posted
Make sure that the column you plan to store the text in supports unicode (nvarchar, ntext, nchar etc) and then simply insert it and select it in the same way you would for normal (English) text
Monday, December 5, 2011 2:36 AM -
User-444409258 posted
dear please solve my problem
how to insert Russia language text into database and how to get data from database asp.net using c sharp
please solve my problem
thanksMonday, December 5, 2011 2:47 AM -
User-444409258 posted
dear not working i can changes this
my datatype is nvarchar(4000) but nor working , its give me that type of text ????????????????????????????????????????????????
when i can insert russia text from the website
please solve my problem
Monday, December 5, 2011 2:54 AM -
User1784393945 posted
how to insert Russia language text into database and how to get data from database asp.net using c sharp
hey there
whenever you need to insert any other language's content into database you will have to use nvarchar, ntext, or nchar type of datatypes in
database columns because these datatypes supports multilingual texts and have Unicode support also. so you need to enter your content in
russian language and save it in database into nvarchar , ntext or nchar columns. and while displaying if you want to convert russian language into
english then you can use google language translator or use resource file in asp.net for multilingual support. Check these links
http://www.codeproject.com/KB/cs/multilingual.aspx
http://www.codeproject.com/KB/cs/multilingual_pplication.aspx
http://www.codeproject.com/KB/cs/Multilingual_application.aspx
Monday, December 5, 2011 2:54 AM -
User-1312722619 posted
Hi,
I am also a developer in Moscow and using Russian text in my application. Are you sure that you are not missing N'' convention?
See following example. INSERT statement has 2 entry. First one is being used by N'' but second one without N''. As long as you use N'' for text types, russian characters will be recognized automatically and you dont need to anytthing. Your client controls will render russian characters without any problem.
CREATE TABLE [dbo].[Table_Test] ( Column1 [nchar](10) NULL ) INSERT INTO [dbo].[Table_Test] ( Column1) VALUES (N'Привет') ,('Привет') SELECT Column1 FROM [dbo].[Table_Test]
Monday, December 5, 2011 2:57 AM -
User-444409258 posted
sorry dear
i dont want like this , i can do this like you. but when i insert ruussian text from admin side website page its give me like that text when i can insert ??????????????????????????????????????????????????????????????????????????????????????
so my data type also correct and when i can edit in database and i can write russain text its working but on webiste when i can insert its not working , give me that message ???????????????????????????????????????
so please give me the code of c# how can i insert russian text
english text is working and insert normally .
thanks
Monday, December 5, 2011 5:00 AM -
User-1312722619 posted
Hi,
How is your INSERT statement look like? Which control are you using to INSERT data, SqlDataSource or etc?
Monday, December 5, 2011 5:15 AM -
User-444409258 posted
default.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<h3>
Home Page text Change</h3>
<table>
<tr>
<td>
Title Name: *
</td>
<td>
<asp:TextBox ID="home_Title" runat="server" CssClass="wm" />
</td>
</tr>
<tr>
<td colspan="4" style="text-align: left;">
<h3>
:: Description ::</h3>
</td>
</tr>
<tr>
<td valign="top">
</td>
<td colspan="3">
<asp:TextBox ID="Home_name" runat="server" CssClass="wm" TextMode="MultiLine" Height="302px"
Width="590px" />-
</td>
</tr>
<tr>
<td colspan="2" class="style1">
<asp:Button ID="Add_Home" CssClass="prdbtn" runat="server" Text="Submit" OnClientClick="return checkEmpty();"
OnClick="Add_Home_Click1" />
</td>
</tr>
</table>
</asp:Content>back end code
on default.aspx.cs page
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Text;
public partial class Adm_product_add_Home : System.Web.UI.Page
{
DBcommand DBAcquire = new DBcommand();
protected void Page_Load(object sender, EventArgs e)
{
Label prd_info = new Label();
if (!Page.IsPostBack)
{
string type = Request.QueryString["type"].ToString();
if (type == "add")
{
}
else
{
DBAcquire.open_conn();
int id = DBAcquire.GetID("select catid from Home where Cat='" + Request.QueryString["catid"] + "'");
DBAcquire.new_comm("select Cat, description from Home where catid=" + id + "");
DBAcquire.DBReader();
if (DBAcquire.readDB.Read())
{
home_Title.Text = DBAcquire.readDB.GetValue(0).ToString();
Home_name.Text = DBAcquire.readDB.GetValue(1).ToString();
// prd_info.Text = DBAcquire.readDB.GetValue(1).ToString();
}
DBAcquire.readDB.Close();
DBAcquire.comm.Cancel();
DBAcquire.close_conn();
// Home_name.Content = prd_info.Text;
}
}
}
protected void Add_Home_Click1(object sender, EventArgs e)
{
String type;
type = Request.QueryString["type"].ToString();
if (type == "add")
{
DBAcquire.open_conn();
string state;
int pass = 0;
state = "select max(pos) from Home";
DBAcquire.new_comm(state);
DBAcquire.DBReader();
while (DBAcquire.readDB.Read())
{
if (!DBAcquire.readDB.IsDBNull(0))
{
pass = Convert.ToInt32(DBAcquire.readDB.GetValue(0));
}
}
pass++;
DBAcquire.readDB.Close();
string str;
str = string.Format("insert into Home (Cat, description, pos) values ('" + home_Title.Text + "','" + Home_name.Text + "'," + pass + ")");
DBAcquire.new_comm(str);
DBAcquire.comm.ExecuteNonQuery();
DBAcquire.close_dbcommands();
DBAcquire.close_conn();
}
else
{
DBAcquire.open_conn();
int id = DBAcquire.GetID("select Catid from Home where Cat='" + Request.QueryString["Catid"] + "'");
string qry;
qry = string.Format("update Home set Cat ='" + home_Title.Text + "', description='" + Home_name.Text + "' where Catid=" + id + "");
DBAcquire.new_comm(qry);
Response.Write(qry);
DBAcquire.executecommand();
DBAcquire.comm.Cancel();
DBAcquire.close_conn();
}
Response.Redirect("default.aspx");
}
}my class code is here DBCommand.cs page code
using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Sql;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
/// <summary>
/// Summary description for DBcommand
/// </summary>
public class DBcommand
{
#region Global Variables
SqlConnection conn;
public SqlCommand comm, comm1;
public SqlDataReader readDB, readDB1;
#endregion
public DBcommand()
{
//
// TODO: Add constructor logic here
//
conn = new SqlConnection();
}
public void open_conn()
{
if (conn.State == System.Data.ConnectionState.Closed)
{
conn.ConnectionString = @"Data Source=ZUBAIRKHALIL-PC\SQLEXPRESS;Initial Catalog=germony;Integrated Security=True;MultipleActiveResultSets=True";
conn.Open();
}
}
public void close_conn()
{
conn.Close();
conn.Dispose();
}
public void new_comm(String query)
{
comm = new SqlCommand(query.ToString().Replace("false", "0").Replace("true", "1").Replace("False", "0").Replace("True", "1").Replace("Ucase", "UPPER").Replace("UCase", "UPPER"), conn);
}
public void new_comm1(String query)
{
comm1 = new SqlCommand(query.ToString().Replace("false", "0").Replace("true", "1").Replace("False", "0").Replace("True", "1").Replace("Ucase", "UPPER").Replace("UCase", "UPPER"), conn);
if (readDB1 != null)
{
readDB1.Close();
}
}
public void DBReader()
{
if (readDB != null)
{
readDB.Close();
}
readDB = comm.ExecuteReader();
}
public void DBReader1()
{
readDB1 = comm1.ExecuteReader();
}
public void close_dbcommands()
{
readDB.Close();
comm.Cancel();
}
public void executecommand()
{
comm.ExecuteNonQuery();
}
public void executefast()
{
comm.ExecuteScalar();
}
public System.Data.DataView get_dataset(String query)
{
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter data = new System.Data.SqlClient.SqlDataAdapter(query.ToString().Replace("false", "0").Replace("true", "1").Replace("False", "0").Replace("True", "1").Replace("Ucase", "UPPER").Replace("UCase", "UPPER"), conn);
data.Fill(ds, "Country_name");
return ds.Tables[0].DefaultView;
}
public System.Data.DataTable GetData(string qry)
{
if (conn.State != System.Data.ConnectionState.Open)
open_conn();
System.Data.DataTable dt = new System.Data.DataTable();
SqlDataAdapter cmd = new SqlDataAdapter(qry.ToString().Replace("false", "0").Replace("true", "1").Replace("False", "0").Replace("True", "1").Replace("Ucase", "UPPER").Replace("UCase", "UPPER"), conn);
cmd.Fill(dt);
return dt;
}
public string Encoder(String pass)
{
try
{
byte[] encData_byte = new byte[pass.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(pass);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;
}
catch (Exception ex)
{
throw new Exception("Error in base64Encode" + ex.Message);
}
}
public string decoder(String pass)
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(pass);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;
}
public string folder_name_encode(String url)
{
url = url.ToString().Replace(" ", "_").Replace("/", "[0]").Replace("<", "[1]").Replace(">", "[2]").Replace(":", "[3]").Replace("*", "[4]").Replace("?", "[5]").Replace("|", "[6]").Replace("\"", "").Replace("\\\\", "[8]");
return url;
}
public string url_split(String url)
{
String[] uri = url.ToLower().Replace("code", "#").Split('#');
return uri[0];
}
public Int32 GetID(string qry)
{
Int32 id = 0;
SqlDataAdapter da = new SqlDataAdapter(qry, conn);
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
id = (dt.Rows.Count > 0) ? Convert.ToInt32(dt.Rows[0][0]) : 0;
return id;
}
public void executenonquery(string query)
{
if (conn.State != System.Data.ConnectionState.Open)
open_conn();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}check this three file i can insert when i click on ADD button then go to the default.aspx page , i can send query string to this page
like this
protected void add_Home_Click(object sender, EventArgs e)
{
string strqry;
strqry = "select catid from Home where cat='" + Home.SelectedItem + "'";
try
{
DBAcquire.open_conn();
DBAcquire.new_comm(strqry);
DBAcquire.DBReader();
int add = 0;
while (DBAcquire.readDB.Read())
{
add = Convert.ToInt32(DBAcquire.readDB.GetValue(0).ToString());
}
Response.Redirect("default.aspx?type=add&catid=" + add + "");
DBAcquire.close_dbcommands();
DBAcquire.close_conn();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}database table code here
CREATE TABLE [dbo].[Home](
[Catid] [int] IDENTITY(1,1) NOT NULL,
[Cat] [nvarchar](4000) NULL,
[Pos] [int] NULL,
[Description] [nvarchar](4000) NULL,
CONSTRAINT [PK_Home] PRIMARY KEY CLUSTERED
(
[Catid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]Monday, December 5, 2011 6:07 AM -
User-1312722619 posted
<meta name="Generator" content="Microsoft Word 12 (filtered medium)" />
Hi,<o:p></o:p>
<o:p> </o:p>
Please use following syntax in your INSERT and UPDATE commands. Try to add N for text parameters <o:p></o:p>
<o:p> </o:p>
str = string.Format("insert into Home (Cat, description, pos) values (N'" + home_Title.Text + "',N'" + Home_name.Text + "'," + pass + ")");<o:p></o:p>
<o:p> </o:p>
qry = string.Format("update Home set Cat = N'" + home_Title.Text + "', description= N'" + Home_name.Text + "' where Catid=" + id + "");<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 5, 2011 7:09 AM -
User-444409258 posted
thanks dear i am very happy , you solve my problem really thanks dear i love you sir .
i am very happy from you, realy you are very very very good teacher.
thanks thanks thanks
Monday, December 5, 2011 7:50 AM -
User-1312722619 posted
(: good
Monday, December 5, 2011 8:03 AM -
User-444409258 posted
can you give me your personal email address , in future its work for me please
Monday, December 5, 2011 8:18 AM