| Bug #66077 | Unicode / Utf8 | ||
|---|---|---|---|
| Submitted: | 29 Jul 2012 21:23 | Modified: | 9 Aug 2012 19:42 |
| Reporter: | Finn Nielsen | Email Updates: | |
| Status: | Not a Bug | Impact on me: | |
| Category: | Connector / NET | Severity: | S3 (Non-critical) |
| Version: | 6.5.4.0 | OS: | Windows |
| Assigned to: | Fernando Gonzalez.Sanchez | CPU Architecture: | Any |
| Tags: | encoding, Getname, getordinal | ||
[6 Aug 2012 18:41]
Finn Nielsen
Same problem with Getname, have to write
With Cmd.ExecuteReader(CommandBehavior.SingleResult)
FieldName = Encoding.UTF8.GetString(Encoding.Default.GetBytes(.GetName(ColNr)))
[9 Aug 2012 15:45]
Fernando Gonzalez.Sanchez
Hi,
Are you using "Character set=utf8" in your connection string?
For example, with the following code seems to work fine (correctly prints 2):
SQL:
CREATE TABLE `tblTitelTekster` (
`TitelTekstID` int(11) NOT NULL,
`TitelTekst` varchar(60) COLLATE utf8_danish_ci NOT NULL,
`Løbenummer` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`TitelTekstID`),
UNIQUE KEY `TitelTekst_Løbenummer_UNIQUE` (`TitelTekst`,`Løbenummer`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci
insert into tblTitelTekster values ( 1, 'hello', 2 )
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace DanishTable
{
class Program
{
static void Main(string[] args)
{
MySqlConnection con = new MySqlConnection("server=localhost; database=test6; user id=xxx; Character set=utf8; ");
MySqlCommand cmd = new MySqlCommand("select * from tblTitelTekster", con);
con.Open();
MySqlDataReader r = cmd.ExecuteReader();
try
{
while (r.Read())
{
int i = r.GetOrdinal("Løbenummer");
Console.WriteLine(i);
}
} finally {
r.Close();
con.Close();
}
}
}
}
[9 Aug 2012 18:40]
Finn Nielsen
Are you using "Character set=utf8" in your connection string? No - sorry. I am now. It did the trick. Thanks a lot.
[9 Aug 2012 19:42]
Fernando Gonzalez.Sanchez
Glad to know, thanks. Closing the issue.

Description: Table (with danish ø): CREATE TABLE `tblTitelTekster` ( `TitelTekstID` int(11) NOT NULL, `TitelTekst` varchar(60) COLLATE utf8_danish_ci NOT NULL, `Løbenummer` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`TitelTekstID`), UNIQUE KEY `TitelTekst_Løbenummer_UNIQUE` (`TitelTekst`,`Løbenummer`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci ------ VB.NET error: Conn.. .. ..ExecuteReader(CommandBehavior.SingleResult) Ordinal = .Getordinal("Løbenummer") 'error ------ have to write Ordinal = .GetOrdinal("Løbenummer") 'ok How to repeat: create the table and the code