sqlserver数据库中Image类型转字符串后乱码

sqlserver数据库中Image类型存储的内容如下(存储的不是图片):
0x94A946BE0B5AB3ECA80E7D4C584B54FD2DE3AA49B97F32E87DF67E2434B10C659207C0A711952215CD660BECB5EBA774DF28C6CA56B1DA7278C19B734590AAB6C17A0259D875AA9872DD31B09680A28AF01CC22FCB995AB2EB2AD54B7CE6FB48DBC754CA9F2925D49058F699CE57639F06CC2FFC5CA1AF049FFF612AAB9A6188890414C51A340E842CAF61D5A02A9840C8AA1EC9EB2D1C423378240018051303770C54BF076D7EF18231DF36DC557BC369D31BA1D6405F4E755959DC04183A81EB364025FECDD6BD9C326E88931AAC7F
我从数据库中先把数据读到byte[]里面,然后用System.Text.Encoding.Default.GetString方法转出来的字符串是乱码,请问要怎样读取才能读到正常的字符串?

4个回答

这是图片二进制转成16进制的结果,你想要什么正常字符串啊,根本没有和字符串的对应关系

目测就应该是乱码,我把我电脑上所有的编码都跑了一次,没有一个能对上

IBM EBCDIC (US-Canada) mz?′!·?y'<ì.èùT??
OEM United States ??F╛Z│∞?}LXKT2-π?I
IBM EBCDIC (International) mz?′]·?y'<ì.èùT??
Arabic (ASMO 708) ╜╚F╓Z╠?╟}LXKT£-?╔I
Arabic (DOS) ¤?F╛Z│??}LXKT2-??I
Greek (DOS) ΦσF╛Z│?ρ}LXKT2-??I
Baltic (DOS) ??F?Z│??}LXKT2-??I
Western European (DOS) ??F¥Z│y?}LXKT2-ò?I
Central European (DOS) ??F?Z│y?}LXKT?-??I
OEM Cyrillic ?ЕFЙZ│Ве}LXKT§-сфI
Turkish (DOS) ??F¥Z│ì?}LXKT2-ò?I
OEM Multilingual Latin I ??F¥Z│y?}LXKT2-ò?I
Portuguese (DOS) ?òF╛Z│∞?}LXKT2-π?I
Icelandic (DOS) ??F╛Z│∞?}LXKT2-π?I
Hebrew (DOS) ??F╛Z│∞?}LXKT2-π?I
French Canadian (DOS) ??F╛Z│∞?}LXKT2-π?I
Arabic (864) ??F?Z???}LXKT?-??I
Nordic (DOS) ??F╛Z│∞?}LXKT2-π?I
Cyrillic (DOS) ФйF╛Z│ьи}LXKT¤-укI
Greek, Modern (DOS) ?ΖFΟZ│σΕ}LXKT?-ιΗI
IBM EBCDIC (Multilingual Latin-2) mz?′]??y'<?.??T??
Thai (Windows) ”?F?Z???}LXKT?-??I
IBM EBCDIC (Greek Modern) mzΖχ]??y'<Ρ.Ν?TνΙ
Japanese (Shift-JIS) 畠F?Z??}LXKT?-罨I?2
Chinese Simplified (GB2312) 敥F?Z踌?}LXKT?悛I?2鑮鰚$4
Korean ?F?Z??}LXKT?丞I?2??$4
Chinese Traditional (Big5) F?Z喬?}LXKT?膋I?2鋑騺$4
IBM EBCDIC (Turkish Latin-5) mz?′?·#y'<ì.èùT??
IBM Latin-1 mz?′!·?y'<ì.èùT??
IBM EBCDIC (US-Canada-Euro) mz?′!·?y'<ì.èùT??
IBM EBCDIC (Germany-Euro) mz?′ü·\y'<ì.èùT??
IBM EBCDIC (Denmark-Norway-Euro) mz?′€·?y'<ì.èùT??
IBM EBCDIC (Finland-Sweden-Euro) mz?′€·@y'<ì.èùT??
IBM EBCDIC (Italy-Euro) mz?′é·?y'<~.}ùT??
IBM EBCDIC (Spain-Euro) mz?′]·?y'<ì.èùT?|
IBM EBCDIC (UK-Euro) mz?′!·?y'<ì.èùT??
IBM EBCDIC (France-Euro) mz?′§·?y'<ì.}ùT??
IBM EBCDIC (International-Euro) mz?′]·?y'<ì.èùT??
IBM EBCDIC (Icelandic-Euro) mz?\?·^y'<ì.èùT??
Unicode ??娋??????羹?⑾?攌??锑?
Unicode (Big-Endian) 钩????経塋哽????緶縤??鈇??∕
Central European (Windows) ”?F?Z?ě¨}LXKTy-??I
Cyrillic (Windows) ”?F?Z?мЁ}LXKTэ-г?I
Western European (Windows) ”?F?Z3ì¨}LXKTy-?aI
Greek (Windows) ”?F?Z3μ¨}LXKT?-γ?I
Turkish (Windows) ”?F?Z3ì¨}LXKT?-?aI
Hebrew (Windows) ”?F?Z3?¨}LXKT?-?×I
Arabic (Windows) ”?F?Z3?¨}LXKT?-??I
Baltic (Windows) ”?F?Z3??}LXKT?-??I
Vietnamese (Windows) ”?F?Z3?¨}LXKT?-?aI
Korean (Johab) ?F?Z??}LXKT?-沂I?2畔馱$
Western European (Mac) ??F?Z≥??}LXKT?-??I
Japanese (Mac) 畠F?Z??}LXKT?-罨I?2
Chinese Traditional (Mac) ?F?Z喬?}LXKT?-膋I?2鋑騺$
Korean (Mac) ???Z??}LXKT?丞I?2??$4
Arabic (Mac) ??F?Z???}LXKT?-??I
Hebrew (Mac) ??F?Z???}LXKT?-??I
Greek (Mac) ??FΨZ≥λ?}LXKT?-ψΣI
Cyrillic (Mac) Ф?F?Z≥м?}LXKTэ-г?I
Chinese Simplified (Mac) ???Z踌?}LXKT?-悛I?2??$
Romanian (Mac) ??F?Z≥??}LXKT?-??I
Ukrainian (Mac) Ф?F?Z≥м?}LXKTэ-г?I
Thai (Mac) ??F?Z???}LXKT?-??I
Central European (Mac) ē?F?Z≥??}LXKT?-??I
Icelandic (Mac) ??F?Z≥??}LXKT?-??I
Turkish (Mac) ??F?Z≥??}LXKT?-??I
Croatian (Mac) ??F?Z≥??}LXKTê-??I
Unicode (UTF-32) ????????????????????
Unicode (UTF-32 Big-Endian) ????????????????????
Chinese Traditional (CNS) ?咶?Z?}LXKT亂I?2曣$4
TCA Taiwan 扣F?Z迋?}LXKT?-I?2??$
Chinese Traditional (Eten) 扣F?Z?袺}LXKT?剒I?2?
IBM5550 Taiwan 宸F?Z烷?}LXKT?-?I?2??~
TeleText Taiwan ???Z征?}LXKT??I?2踆魌$4
Wang Taiwan 姓F?Z峎?}LXKT?-I?2??~
Western European (IA5) ??F?Z???}LXKT?-??I
German (IA5) ??F?Z???üLXKT?-??I
Swedish (IA5) ??F?Z????LXKT?-??I
Norwegian (IA5) ??F?Z????LXKT?-??I
US-ASCII ??F?Z???}LXKT?-??I
T.61 ??F?Z3T¤?LXKT?-a?I
ISO-6937 ?‘F?Z3T¤}LXKT?-?“I
IBM EBCDIC (Germany) mz?′ü·\y'<ì.èùT??
IBM EBCDIC (Denmark-Norway) mz?′¤·?y'<ì.èùT??
IBM EBCDIC (Finland-Sweden) mz?′¤·@y'<ì.èùT??
IBM EBCDIC (Italy) mz?′é·?y'<~.}ùT??
IBM EBCDIC (Spain) mz?′]·?y'<ì.èùT?|
IBM EBCDIC (UK) mz?′!·?y'<ì.èùT??
IBM EBCDIC (Japanese katakana) ????!t??'<?.??T??
IBM EBCDIC (France) mz?′§·?y'<ì.}ùT??
IBM EBCDIC (Arabic) mz??!??y'<?.??T??
IBM EBCDIC (Greek) mzΖχ]??y'<Ρ.Ν?TνΙ
IBM EBCDIC (Hebrew) mz?′!??y'<?.??T??
IBM EBCDIC (Korean Extended) mz??!??y'<?.??T??
IBM EBCDIC (Thai) mz??!??y'<?.??T?[
Cyrillic (KOI8-R) ■╘F╬ZЁЛ╗}LXKTЩ-Ц╙I
IBM EBCDIC (Icelandic) mz?\?·^y'<ì.èùT??
IBM EBCDIC (Cyrillic Russian) mz?Ф]шЖy'<№.?ЩTр?
IBM EBCDIC (Turkish) mz?′?}#y'<ì.èùT??
IBM Latin-1 mz??!·?y'<ì.èùT??
Japanese (JIS 0208-1990 and 0212-1990) ???Z褐?}LXKT礫I?2馲$4
Chinese Simplified (GB2312-80) ???Z踌?}LXKT?-悛I?2??$
Korean Wansung ???Z??}LXKT?丞I?2??$4
IBM EBCDIC (Cyrillic Serbian-Bulgarian) mz?Ф]шЖy'<№.?ЩTр?
Cyrillic (KOI8-U) ■╘F?ZЁЛ╗}LXKTЩ-Ц╙I
Western European (ISO) ??F?Z3ì¨}LXKTy-?aI
Central European (ISO) ??F?Z?ě¨}LXKTy-??I
Latin 3 (ISO) ??F?Z3ì¨}LXKT?-??I
Baltic (ISO) ??F?Z??¨}LXKT?-?ēI
Cyrillic (ISO) ??FОZГь?}LXKT§-у?I
Arabic (ISO) ??F?Z???}LXKT?-??I
Greek (ISO) ??F?Z3μ¨}LXKT?-γ?I
Hebrew (ISO-Visual) ??F?Z3?¨}LXKT?-?×I
Turkish (ISO) ??F?Z3ì¨}LXKT?-?aI
Estonian (ISO) ??F?Z3??}LXKT?-??I
Latin 9 (ISO) ??F?Z3ì?}LXKTy-?aI
Europa ?ΔF?♂Z│σγ?}LXKTω-ΠδI
Hebrew (ISO-Logical) ??F?Z3?¨}LXKT?-?×I
Japanese (JIS) ??F?Z??????????????
Japanese (JIS-Allow 1 byte Kana) ??F?Z??????????????
Japanese (JIS-Allow 1 byte Kana - SO/SI) ??F?Z??????????????
Korean (ISO) ??F?Z???休靺????????
Chinese Simplified (ISO-2022) 敥F?Z踌?}LXKT?悛I?2鑮鰚$4
Japanese (EUC) ???Z褐?}LXKT?礫I?2??$4
Chinese Simplified (EUC) 敥F?Z踌?}LXKT?悛I?2鑮鰚$4
Korean (EUC) ???Z??}LXKT?丞I?2??$4
Chinese Simplified (HZ) ??F?Z???}LXKT?-??I
Chinese Simplified (GB18030) 敥F?Z踌?}LXKT?-悛I?2
ISCII Devanagari ??F?Z???}LXKT?-??I
ISCII Bengali ??F?Z???}LXKT?-??I
ISCII Tamil ??F?Z???}LXKT?-??I
ISCII Telugu ??F?Z???}LXKT?-??I
ISCII Assamese ??F?Z???}LXKT?-??I
ISCII Oriya ??F?Z???}LXKT?-??I
ISCII Kannada ??F?Z???}LXKT?-??I
ISCII Malayalam ??F?Z???}LXKT?-??I
ISCII Gujarati ??F?Z???}LXKT?-??I
ISCII Punjabi ??F?Z???}LXKT?-??I
Unicode (UTF-7) ??F?Z3ì¨}LXKTy-?aI
Unicode (UTF-8) ??F?Z??}LXKT?-?I?
Press any key to continue . . .

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "94A946BE0B5AB3ECA80E7D4C584B54FD2DE3AA49B97F32E87DF67E2434B10C659207C0A711952215CD660BECB5EBA774DF28C6CA56B1DA7278C19B734590AAB6C17A0259D875AA9872DD31B09680A28AF01CC22FCB995AB2EB2AD54B7CE6FB48DBC754CA9F2925D49058F699CE57639F06CC2FFC5CA1AF049FFF612AAB9A6188890414C51A340E842CAF61D5A02A9840C8AA1EC9EB2D1C423378240018051303770C54BF076D7EF18231DF36DC557BC369D31BA1D6405F4E755959DC04183A81EB364025FECDD6BD9C326E88931AAC7F";
            var query = Regex.Matches(s, "[A-F0-9]{2}").Cast<Match>().Select(x => Convert.ToByte(x.Value, 16)).ToArray();
            foreach (var item in Encoding.GetEncodings())
            {
                string r = Encoding.GetEncoding(item.CodePage).GetString(query);
                Console.WriteLine(item.DisplayName + " " + r.Substring(0, 20));
            }
        }
    }
}

楼主存储的是图片 为啥要转成字符串 ?

先直接打印图片的二进制。然后看你数据库中数据对比。看是否数据如何转换的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问