Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am trying to insert non English character in SQL from ASP.NET, but it is inserting N????
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:
insert into item (item_name) values(N'अंगूर')
Posted 11-Dec-12 1:20am
Edited 11-Dec-12 9:11am
v2
Comments
AnkitGoel.com at 11-Dec-12 7:26am
   
please share create script of table client_billing_address
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

@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 :
INSERT INTO dbo.client_billing_address (vc_firstname_on_credit_card )
                VALUES(@vc_firstname_on_credit_card)
  Permalink  
Comments
mrinal_kumar_jha at 12-Dec-12 0:40am
   
i am doing same but not working ..Still ??? in database
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

change your sp as:
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

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();
            }
        }
     
}
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100