Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am Inserting Arabic currency symbol but Symbol but inserting in question mark form "?"
I have defined Database Field in this form [Currency_Symbol	nvarchar(10)]


What I have tried:

Dim Insert_Symbol As New SqlCommand("Insert into Currency.dbo.Currency_Symbol (Currency_Symbol) values ('" & CountryCurrency_Symbol & "')", SQLCon)
Insert_Symbol.ExecuteNonQuery()
Posted
Updated 12-Jan-19 5:04am

Two things:
1) The stored character needs the right font in order to display it correctly.
Depending on how you are displaying it, unless you use the correct font you will probably get a question mark instead.
2) Try sending it as a NVARCHAR string instead of a VARCHAR:
Dim Insert_Symbol As New SqlCommand("Insert into Currency.dbo.Currency_Symbol (Currency_Symbol) values (N'" & CountryCurrency_Symbol & "')", SQLCon)
may help. Or better, pass it as a parameter via a parameterized query instead and let the system sort it out. Concatenating strings to form SQL commands is not a safe way to do things: it leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
 
Share this answer
 
you put an N before a string literal to make it Unicode. For example: insert into table (name) values (N'XYZ').)


Dim Insert_Symbol As New SqlCommand("Insert into Currency.dbo.Currency_Symbol (Currency_Symbol) values (N'" & CountryCurrency_Symbol & "')", SQLCon)
Insert_Symbol.ExecuteNonQuery()


Please refer to a link below
How to insert arabic characters into sql database? - Stack Overflow[^]
 
Share this answer
 
v2
As explained in the previous answer, using an nvarchar parameter should fix the problem as long as the column is also defined as nvarchar.

To add to that, looking at the code, it seems to lack some important aspects like
- using statements to ensure proper disposal of the objects
- error handling to manage and inform about the errors
- and so on.

I would recommend going through article Properly executing database operations[^] [^]
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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