Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am trying to insert non English character in SQL from ASP.NET, but it is inserting N????
SQL
CREATE PROCEDURE [dbo].[client_billing_address_sp_update] 
(
@in_type tinyint,
@vc_firstname_on_credit_card nvarchar(50) = ''
) 
AS
IF(@in_type = 1) 
BEGIN
INSERT INTO dbo.client_billing_address (vc_firstname_on_credit_card )
                VALUES('N'+@vc_firstname_on_credit_card)
END

Why it is inserting N????
If I use the following statement it works:
SQL
insert into item (item_name) values(N'अंगूर')
Posted
Updated 11-Dec-12 9:11am
v2
Comments
AnkitGoel.com 11-Dec-12 7:26am    
please share create script of table client_billing_address

@vc_firstname_on_credit_card is already declared as nvarchar(50)
so you don't need to write 'N'+@vc_firstname_on_credit_card. Just use :
SQL
INSERT INTO dbo.client_billing_address (vc_firstname_on_credit_card )
                VALUES(@vc_firstname_on_credit_card)
 
Share this answer
 
Comments
k@ran 12-Dec-12 0:40am    
i am doing same but not working ..Still ??? in database
When dealing with Unicode string constants in SQL Server you must precede all Unicode strings with a capital letter N, as documented in the SQL Server Books Online topic "Using Unicode Data". The "N" prefix stands for National Language in the SQL-92 standard, and must be uppercase. If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string.
-------
NVarchar is used for Unicode. If your database is not storing multilingual Data you can keep using Varchar. As an example: N'abc' simply converts your string to unicode.
 
Share this answer
 
v2
change your sp as:
SQL
CREATE PROCEDURE [dbo].[client_billing_address_sp_update] 
(
@in_type tinyint,
@vc_firstname_on_credit_card nvarchar(50) = ''
) 
AS
declare @sql1 nvarchar(max)  
IF(@in_type = 1) 
BEGIN
set @sql1='insert into FCM_Claims(vc_firstname_on_credit_card) values(N'''+ @vc_firstname_on_credit_card  + ''')';
END 
exec(@sql1);


Try this function from your cs file

C#
public Void InsertNonEnglish(string in_type,string vc_firstname_on_credit_card){
string  ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
      
        SqlConnection con = null;
        try
        {
            con = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand("client_billing_address_sp_update", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] prm=new SqlParameter[2];

            cmd.Parameters.Add("@in_type ", SqlDbType.TinyInt).Value = in_type;
            cmd.Parameters.Add("@vc_firstname_on_credit_card ", SqlDbType.NVarChar, 1024).Value = vc_firstname_on_credit_card;
        
            con.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            if (con != null)
            {
                con.Close();
                con.Dispose();
            }
        }
     
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900