日期:2014-05-17  浏览次数:21037 次

大家觉得,存储用户的头像该如何存?
public partial class Form1: Form {
        #region 多次用到成员变量.
        private DataSet set = new DataSet();    //存储Adapter读取的数据集.
        private SqlDataAdapter adapter;
        private string strConnction = @"Data Source=.\SQLExpress;Initial Catalog=DB_User;Persist Security Info=True;User ID=sa;Password=**********";
        #endregion

        public Form1() {
            InitializeComponent();
        }
        //选择用户头像.
        private void btnSelectImg_Click(object sender, EventArgs e) {
            openFD.Filter = "(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";//图像过滤.
            if(openFD.ShowDialog() == DialogResult.OK) picBox.Image = Image.FromFile(openFD.FileName);
        }
        //添加用户方法.
        bool AddUser(string strName, string strPicture) {
            using(SqlConnection connect = new SqlConnection(strConnction)) {
                using(FileStream fs = new FileStream(strPicture, FileMode.Open, FileAccess.Read)) {
                    using(BinaryReader bReader = new BinaryReader(fs)) {    //二进制读取图像.
                        byte[] bytes = bReader.ReadBytes((int)fs.Length);
                        SqlCommand cmd = connect.CreateCommand();
                        cmd.CommandText = "insert into [dbo].[T_User](FName,FPhoto) values(@name,@photo)";