数据库的数据如下:
id | calldate | md5 | monid | result | poptype | cnt |
2 | 2008-11-28 0:00:00 | 11ssseewwd | 1 | 0 | 0 | 400 |
通过Sql转换成十六进制:
select CallDate,convert(varbinary,Monid)monid,convert(varbinary,Result) result,PopType,sum(Cnt)
from table1
group by CallDate,Monid,Result,PopType order by CallDate,Monid,Result
得到的数据如下:
2008-11-28 00:00:00.000 0x00000001 0x00000000 0 400
要把0x00000001显示到GridView里,需进行转换,如下:
dt为DataTable,是查询的结果。
for (int i = 0; i < dt.Rows.Count; i++)
{
byte[] obj = (byte[])dt.Rows[i]["monid"];
StringBuilder sbmonid = new StringBuilder();
foreach (byte b in obj)
{
sbmonid.Append(b > 15 ? Convert.ToString(b, 16) : '0' + Convert.ToString(b, 16));
}
dt.Rows[i]["monidBin"] = "0x" + sbmonid.ToString();
byte[] objresult = (byte[])dt.Rows[i]["result"];
StringBuilder sbresult = new StringBuilder();
foreach (byte b in objresult)
{
sbresult.Append(b > 15 ? Convert.ToString(b, 16) : '0' + Convert.ToString(b, 16));
}
dt.Rows[i]["resultBin"] = "0x" + sbresult.ToString();
}