//2进制方式 取出数据
tring sql ="select cast (AcctName as binary(5000)) from Account where FormID = 70794";
// SqlHelper.ExecuteScalar 直接准换 bytes
//byte[] bytes = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null) as byte[];
SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null);
rdr.Read();
byte[] b = rdr[0] as byte[];
//转换编码格式
string s = Encoding.UTF8.GetString(b);
//去掉后边补齐的
tring sql ="select cast (AcctName as binary(5000)) from Account where FormID = 70794";
// SqlHelper.ExecuteScalar 直接准换 bytes
//byte[] bytes = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null) as byte[];
SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null);
rdr.Read();
byte[] b = rdr[0] as byte[];
//转换编码格式
string s = Encoding.UTF8.GetString(b);
//去掉后边补齐的
本文介绍了一种使用SQL从数据库中以二进制格式读取数据的方法,并演示了如何将获取到的二进制数据转换为UTF-8编码的字符串。具体步骤包括构建SQL查询语句来获取指定ID的账户名称的二进制表示,通过SqlHelper执行查询并读取结果集,最后将得到的字节数组转换为字符串。
591

被折叠的 条评论
为什么被折叠?



