hello,
my Character type in dbf is BIG5. but I'd like to save in UNICODE.
could you tell me how to save my dbf in unicode mode?
hello,
my Character type in dbf is BIG5. but I'd like to save in UNICODE.
could you tell me how to save my dbf in unicode mode?
Carol,
I made a sample for you as following and attached a simple data as well, see following code:
string originalDbfPathFile = @"..\Post7755Dbf.dbf";
string destDbfPathFile = @"..\Test.dbf";
Encoding sourceEncoding = Encoding.GetEncoding("big5");
Encoding destEncoding = Encoding.UTF8;
private void ChangeDbfEncoding(string originalDbfPathFile, string destDbfPathFile, Encoding sourceEncoding, Encoding destEncoding)
{
GeoDbf originalDbfFile = new GeoDbf(originalDbfPathFile, DbfReadWriteMode.ReadOnly);
originalDbfFile.Encoding = sourceEncoding;
System.Collections.ObjectModel.Collection<DbfColumn> dbfColumns = new System.Collections.ObjectModel.Collection<DbfColumn>();
originalDbfFile.Open();
for (int k = 1; k <= originalDbfFile.ColumnCount; k++)
{
DbfColumn dbfColumn = originalDbfFile.GetColumn(k);
dbfColumns.Add(dbfColumn);
}
originalDbfFile.Close();
GeoDbf.CreateDbfFile(destDbfPathFile, dbfColumns, OverwriteMode.Overwrite, destEncoding);
GeoDbf targetDbfFile = new GeoDbf(destDbfPathFile, DbfReadWriteMode.ReadWrite);
targetDbfFile.Encoding = destEncoding;
try
{
originalDbfFile.Open();
targetDbfFile.Open();
for (int i = 1; i <=originalDbfFile.RecordCount; i++)
{
System.Collections.Generic.Dictionary<string, object> recordInfo = originalDbfFile.ReadRecord(i);
targetDbfFile.WriteRecord(i, recordInfo.Values);
}
}
finally
{
targetDbfFile.Close();
originalDbfFile.Close();
}
}
Any more questions just feel free to let us know.
Thanks.
Yale
Post7755Dbf.zip (229 Bytes)
Thanks for your code, Yale
But it shows error Message: The Value you input is too long. (so, I can’t save dbf completely.)
Other problem,
If I save dbf in UTF-8 and I try to use ExecuteQuery to get results.
string str=Encoding.UTF8.GetString(Encoding.GetEncoding(“big5”).GetBytes(“中文”));
“SELECT TOP 10 FROM ROAD WHERE ROADNAME Like ‘%str%’”
The result is null.
If I use original dbf and use ExecuteQuery to get results. the result is not null.
can you tell me where is wrong?
Carol,
Thanks for your post and questions.
I am not exactly sure when the error message was shown? It is when we create the empty file with dbf columns added or when we insert records?
You may already have known that, for a given characters the character lengths between different encodings are different, for example "中文" which take 4 characters in BIG5 encoding may need 6 or more characters in UNITCODE encoding.
If this problem happens in the header of the dbf, that is to say it will be happening in the API CreateDbfFile, and then we may need to get the column shorter than 10 characters in the target encoding system.
If this problem happens when we inserting some records into the dbf, that means the column header length is ok, while some record content is greater than the length given for the column in the target encoding system, we may need to make it longer length.
About the other problem you mentioned below, could you send me the data both in UTF-8 and big5; it would be ideal if you could send us a small sample application to recreate it.
Any more questions just feel free to let me know.
Thanks.
Yale