当前位置:编程学习 > C#/ASP.NET >>

大家帮忙看看这句话,怎么写啊!!?

      private void SetStudentData(IDataReader idr, StudentInfo studentInfo)
        {
            studentInfo.Name = idr.GetString(0);
            studentInfo.Sex = idr.GetBoolean(1);
            studentInfo.Birthday = idr.GetDateTime(2);
            studentInfo.Nation = idr.GetString(3);
            studentInfo.NationPlace = idr.GetString(4);
            studentInfo.Address = idr.GetString(5);
            studentInfo.Image = (byte[])idr.GetValue(6);//就这句话怎么写啊  
            studentInfo.Memo = idr.GetString(7);
            studentInfo.StudentStatus = idr.GetString(8);
        }

studentInfo.image 是 byte[] 类型;
数据库中是 image 类型; --------------------编程问答-------------------- System.IO.FileStream   fs   =   new   System.IO.FileStream(imagePath,   System.IO.FileMode.Open,   System.IO.FileAccess.Read);   
  byte[]   b   =   new   byte[fs.Length];   
  fs.Read(b,   0,   b.Length);   
  fs.Close();   

或者

 Stream   myStream=new   MemoryStream();   
  bitmap.Save(myStream,img.RawFormat);   
  int   imgdatalen   =Convert.ToInt32(myStream.Length);   
  myStream.Position   =   0;   
  BinaryReader   br   =   new   BinaryReader(myStream);   
  byte[]   imagebyte=br.ReadBytes((int)myStream.Length);   
  br.Close();   
  myStream.Close();



--------------------编程问答-------------------- (byte[])idr[6];
(byte[])idr["name"]; --------------------编程问答-------------------- studentInfo.Image = Image.FromStream(new MemoryStream(idr.GetValue(6) as byte[]));
试试 --------------------编程问答-------------------- 1楼的在做什么? --------------------编程问答--------------------

 
  if(   rdr["image字段"]   !=   System.DbNull.Value   )   
  {   
      byte[]   bimage   =   (byte[])rdr["image字段"];   
  }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,