日期:2014-05-19  浏览次数:20751 次

问个数据存储的问题,就10分,别嫌少啊
private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        string   pathName;
                        if   (this.openFileDialog1.ShowDialog()   ==   System.Windows.Forms.DialogResult.OK)
                        {
                                pathName   =   this.openFileDialog1.FileName;
                                System.Drawing.Image   img   =   System.Drawing.Image.FromFile(pathName);
                                this.pictureBox1.Image   =   img;

                                //将图像读入到字节数组
                                System.IO.FileStream   fs   =   new   System.IO.FileStream(pathName,   System.IO.FileMode.Open,   System.IO.FileAccess.Read);
                                byte[]   buffByte   =   new   byte[fs.Length];
                                fs.Read(buffByte,   0,   (int)fs.Length);
                                fs.Close();
                                fs   =   null;
                                SqlConnection   sqlConnection1   =   new   SqlConnection( "Data   Source=.;Initial   Catalog=111;Integrated   Security=True ");
                                SqlCommand   sqlCommand1   =   new   SqlCommand();
                                //建立Command命令
                                string   comm   =   @ "Insert   into   table1(img,name)   values(@img,@name) ";
                             
                        sqlCommand1.CommandType   =   System.Data.CommandType.Text;
                              sqlCommand1.CommandText   =   comm;
                          sqlCommand1.Connection   =   sqlConnection1;
                  &nb