将数据表列中的字节数组转换为字符串?
我有一个数据表 customerTbl,我单步执行行
foreach (DataRow row in customerTbl.Rows)
{
string CustomerID = row["Customer ID"].ToString();
}
但是,列 Customer ID 返回 byte[]。如何将其转换为字符串(CustomerID)?
我尝试了类似的方法
string CustomerID = Convert.ToBase64String(row["Customer ID"]);
,但显然不起作用
提前致谢
I have a datatable customerTbl and I step through the rows
foreach (DataRow row in customerTbl.Rows)
{
string CustomerID = row["Customer ID"].ToString();
}
However, the column Customer ID returns byte[]. How can I convert this to a string (CustomerID)?
I tried something like
string CustomerID = Convert.ToBase64String(row["Customer ID"]);
but it obviously doesn't work
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据字节的编码,您需要正确的
Encoding
对象来执行转换。假设它是 ASCII,您可以执行以下操作:如果采用不同的编码(UTF8、UTF16 等),请使用适当的编码。
Depending on the encoding of the bytes, you'd need the correct
Encoding
object to perform the conversion. Assuming it is ASCII, you can do this:If in a different encoding (UTF8, UTF16, etc.), use the appropriate one.