c# 如何读取mysql blob 类型的二进制数据
1个回答
展开全部
写:
说明:QueryFile字段为blod类型
private bool SaveQuery(String content)
{
byte[] byts = new System.Text.UnicodeEncoding().GetBytes(content);
assistant ast = new assistant();
MySqlParameter[] param = new MySqlParameter[5];
TimeSpan nowtimespan = new TimeSpan(DateTime.Now.Ticks);
param[0] = new MySqlParameter("@CQID", nowtimespan);
param[1] = new MySqlParameter("@userID", Session["OfficerID"].ToString());
param[2] = new MySqlParameter("@QueryFile", byts);
param[3] = new MySqlParameter("@filename", filename.Text);
param[4] = new MySqlParameter("@fcomment", Comment.Text);
ast.insertCQ(param);
return true;
}
读:
说明:2为blod数据类型的索引
protected void setSelect(String uderid)
{
String sqlcommand = String.Format("select * from CustomQuery where CQID='{0}'", uderid);
MySqlDataReader msr = dh. getReader(sqlcommand,null);
msr.Read();
Byte[] blob = new Byte[(msr.GetBytes(2, 0, null, 0, int.MaxValue))];
msr.GetBytes(2, 0, blob, 0, blob.Length);
msr.Close();
msr.Dispose();
String xmlStr = Encoding.Unicode.GetString(blob);
query.LoadFromString(xmlStr);
}
最简单就是:选出blob数据到DataTable强制类型转化为Byte[]再用 Encoding.Unicode.GetString(Byte[],)转化。
说明:QueryFile字段为blod类型
private bool SaveQuery(String content)
{
byte[] byts = new System.Text.UnicodeEncoding().GetBytes(content);
assistant ast = new assistant();
MySqlParameter[] param = new MySqlParameter[5];
TimeSpan nowtimespan = new TimeSpan(DateTime.Now.Ticks);
param[0] = new MySqlParameter("@CQID", nowtimespan);
param[1] = new MySqlParameter("@userID", Session["OfficerID"].ToString());
param[2] = new MySqlParameter("@QueryFile", byts);
param[3] = new MySqlParameter("@filename", filename.Text);
param[4] = new MySqlParameter("@fcomment", Comment.Text);
ast.insertCQ(param);
return true;
}
读:
说明:2为blod数据类型的索引
protected void setSelect(String uderid)
{
String sqlcommand = String.Format("select * from CustomQuery where CQID='{0}'", uderid);
MySqlDataReader msr = dh. getReader(sqlcommand,null);
msr.Read();
Byte[] blob = new Byte[(msr.GetBytes(2, 0, null, 0, int.MaxValue))];
msr.GetBytes(2, 0, blob, 0, blob.Length);
msr.Close();
msr.Dispose();
String xmlStr = Encoding.Unicode.GetString(blob);
query.LoadFromString(xmlStr);
}
最简单就是:选出blob数据到DataTable强制类型转化为Byte[]再用 Encoding.Unicode.GetString(Byte[],)转化。
追问
你别复制了不中?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询