发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
序列化
//序列化
public byte[] SerializeObject(object pObj)
{
if(pObj == null)
return null;
System.IO.MemoryStream _memory = new System.IO.MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(_memory,pObj);
_memory.Position = 0;
byte[] read = new byte[_memory.Length];
_memory.Read(read,0,read.Length);
_memory.Close();
return read;
}
如果你只是直接将信息保存到数据库,沒有必要序列化
string conn_str = System.Configuration.ConfigurationSettings.AppSettings[ "conn_str "].ToString();
string sREQUEST_ID = Session[ "REQUEST_ID "].ToString();
OleDbConnection cn = new OleDbConnection(conn_str);
cn.Open();
OleDbCommand cmd = new OleDbCommand( "UPDATE REQUEST_MASTER SET REQUEST_FILE=? WHERE REQUEST_ID= " +int.Parse(sREQUEST_ID),cn);
cmd.Parameters.Add( "REQUEST_FILE ",OleDbType.Binary);
if(!sFileName1.Equals( " "))
{
try
{
FileStream fs = new FileStream(Path +sFileName1, FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData1= new byte[fs.Length];
fs.Read(MyData1, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
cmd.Parameters[ "REQUEST_FILE "].Value = MyData1;
}
catch(Exception err)
{
string s = err.Message;
}
}
else
{
cmd.Parameters[ "REQUEST_FILE "].Value = MyData;
}
try
{
cmd.ExecuteNonQuery();
}
catch(Exception e1)
{
}
finally
{
cn.Close();
}
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。