以下是代码是从数据库中读取序列化数据
int ID;
string strcmd = "select * from t_Rights";
string strConn = "Data source=.;database=kokeng;UID=sa;PWD=Win";
using (SqlConnection conn = new SqlConnection(strConn))
{
SqlCommand cmd = new SqlCommand(strcmd, conn);
conn.Open();
using (SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (myReader.Read())
{
ID =Convert.ToInt32( myReader["ID"]);
System.Data.SqlTypes.SqlBytes bytes = myReader.GetSqlBytes(1);
BinaryFormatter bf = new BinaryFormatter();
Rights right = (bf.Deserialize(bytes.Stream)) as Rights;
Console.WriteLine("没有用的ID为{0}",ID);
Console.WriteLine(" ID:{0}\n 实体名:{1}\n 标题:{2}\n 状态:{3}\n 级别:{4}",
right.Id,right.ModelName,right.RightsCaption,right.RightsState,right.ParentLevelRightsName);
}
}
}
Console.ReadKey();
}
连接上一篇文章