3

I have this string that I want to insert into a table:

 string command = @" insert into " + txnDC.Connection.Database + "..[AZGetPackages] ( [PackageID] , [PackageName] , [VendorID] , [VendorDisplayName] , [IsCustom] , [EPCustomerID] )" +
                    @"values( N'1', N'Package 1', N'11', N'Vendor 1', N'0', N''),
                    ( N'2', N'Package 2', N'12', N'Vendor 2', N'0', N''),
                    ( N'3', N'Package 3', N'13', N'Vendor 3', N'0', N''),
                    ( N'4', N'雑誌コード', N'14', N'税込', N'0', N'')";

When I put a breakpoint right after the that line and I view the string in debug it shows up like this:

 txnDC.ExecuteCommand(command, new object[0]); << breakpoint here to view command var

and shows || for the chinese chars.

The pipes are actually those little rectangles.

So when it does the insert to the table it inserts the rectangle characters and not the actual ones I have set.

Anyone have any advice here?

Thanks!

8
  • That string looks like SQL, not C#. Can you explain how that even compiles? Commented Jun 4, 2013 at 19:24
  • 1
    Then you have not shown us the most critical bits - how to you put this string in the database and what the column definition that it is supposed to go to is. Commented Jun 4, 2013 at 19:27
  • 2
    The little rectangles mean "this font doesn't support this character". They're not actually rectangles. Try cutting and pasting the string with the rectangles into an editor that lets you change the font and see what you get. Commented Jun 4, 2013 at 19:28
  • 1
    Thanks Eric, when I cut and paste the chars into Stackoverflow, they show up correctly and they show up correctly in my assignment string too in the CS file. it's just when running in debug and when the code gets executed that char integrity is lost and it's inserted wrongly into DB. Commented Jun 4, 2013 at 19:34
  • 1
    The question therefore ought to be: "My code works fine, but the default font that is used to display the contents of strings in little tooltips during debugging, is a "poor" font which shows replacement characters instead of Chinese Han characters. Why did they choose a poor font? And is it possible to switch to a better (richer) font?" Commented Jun 4, 2013 at 19:58

2 Answers 2

1

I have run the exact same code on someone else's machine and it works there as expected, without any changes. This seems to be a display issue on my system. The only out of the ordinary thing that happened was that I went away on vacation and left my machine off for 10 days. I know that's probably irrelevant but it seems to have done something to my system related to fonts. And no one touched my machine while I was away, and I didn't do anything font related before I went away.

But there's a twist, Notepad won't display the chinese chars, neither will the VS debugger, not the SQL SSMS grid results view. But VS .CS file string var def will and If I paste into the SSMS editor it will show them too.

Insane!

Sign up to request clarification or add additional context in comments.

1 Comment

I feel your pain - I've had a very similar issue where I spend a long time trying to track down a bug that turned out to be a font display problem on my development PC. It broke some applications and not others. I never got to the bottom of it.
0

OK, I'm not sure what you're doing exactly, but you'll be better off using parameterized queries. So maybe something like this (this is pseudo-code so it will need modified to compile):

using (SqlConnection c = new SqlConnection("..."))
{
    c.Open();
    using (SqlCommand cmd = new SqlCommand("INSERT INTO table (...) VALUES (@field1, ...)", c);
    {
        cmd.Parameters.AddWithValue("@field1", "税込");
        cmd.Parameters[0].SqlDbType = SqlDbType.NVarChar;

        cmd.ExecuteNonQuery();
    }
}

9 Comments

Thanks for your reply. Yes I see what you mean, unfortunately, this file is given to me from a macro in excel which generates as I've presented above using the SQL N notation, which should work.
@user1013388: Is the underlying data type of the field nvarchar?
Yes, the data type is NVARCHAR
@user1013388: So how are you sure the data in the database is wrong? If it's the write hex character when you insert it, regardless of whether or not the application can render it, the data is correct.
@user1013388: And what font are you writing it with? The problem is likely that you're using the wrong font, not that there's something wrong with the database.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.