byte[] byearray = UnicodeEncoding.GetBytes(ds.Tables["productphone"].Rows[0]["picdetail"]);

解决方案 »

  1.   

    SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("SqlCon").ToString());
    SqlDataAdapter da=new SqlDataAdapter("select picdetail,pictype,picbytesize,picname from t_picture where picid=1",con);
    DataSet ds=new DataSet();
    da.Fill(ds,"tet");
    int rowcount=ds.Tables[0].Rows.Count;
    byte[] byearray=(byte[])ds.Tables[0].Rows[0]["picdetail"];
    Response.ContentType = ds.Tables[0].Rows[0]["pictype"].ToString();       //输出的类型 
    Response.BinaryWrite(byearray);
    Response.End();
    以上是我从数据库中读取生成图片的代码,
    byte[] byearray=(byte[])ds.Tables[0].Rows[0]["picdetail"];好像有点问题。
      

  2.   

    TonyJoule(寒星㊣) 还是出错。无法从object转换成char【】
      

  3.   

    没有人知道这条语句该如何写吗?byte[] byearray = UnicodeEncoding.GetBytes(ds.Tables["productphone"].Rows[0]["picdetail"]);
    出错
      

  4.   

    ds出来的都是object类型
    你可以用convert.tochar转一下
    试试getbytes方法其他的重载
      

  5.   

    use sqldatareader getbytes function
      

  6.   

    jgbeaver(千里眼) 说的有道理
      

  7.   

    OleDbConnection oleconnection=new OleDbConnection();
    oleconnection.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\文档\毕业设计\项目\bysj.mdb";
    OleDbCommand olecommand=new OleDbCommand("insert into abc(a,b) values('ahjh',?)",oleconnection);
    string str=@"D:\Documents and Settings\my\桌面\MKMPlan.dwg";
    FileStream file =  new FileStream(str,FileMode.Open, FileAccess.Read);
    Byte[] bytBLOBData = new Byte[file.Length]; 
    file.Read(bytBLOBData, 0, bytBLOBData.Length);
    file.Close();
    olecommand.Parameters.Add(new OleDbParameter("jpeg",OleDbType.Binary,bytBLOBData.Length,ParameterDirection.Input,true,0,0,null,DataRowVersion.Default,bytBLOBData));
    oleconnection.Open();
    olecommand.ExecuteNonQuery();
    oleconnection.Close();
    (上面是把某图片写入数据库)
    (上面是把某图片写入数据库)
    (下面是从数据库中调出图片)
    oleDbConnection1.Open(); oleDbDataAdapter1.Fill(ds1);
    Byte[] byteBLOBData =  new Byte[0];
    byteBLOBData = (Byte[])(ds1.Tables["abc"].Rows[0]["b"]);
    MemoryStream stmBLOBData = new MemoryStream();
                 pictureBox1.Image=Image.FromStream(stmBLOBData);
    说明:在我的表[abc]中存有'长二进制文件'类型字段“b”;
      

  8.   

    多谢 feigehao(gaosou) 的指点。
    byte[] byearray=(byte[])ds.Tables[0].Rows[0]["picdetail"];这句没有问题。。
      

  9.   

    是我把图片放入数据库中的时候出了问题  HttpPostedFile UpFile = UP_FILE.PostedFile;
      int fileLength =UpFile.ContentLength;
      string filetype;
      string fname ;
      filetype = UpFile.ContentType;
      byte [] fileByteArray=new byte[fileLength];
      System.IO.Stream streamObject = UpFile.InputStream;
      streamObject.Read(fileByteArray, 0, fileLength);
      fname = Path.GetFileName(UpFile.FileName);
      if (fname!="")
     {
       string str_con=System.Configuration.ConfigurationSettings.AppSettings.Get("SqlCon").ToString();
       SqlConnection con = new SqlConnection(str_con);
       con.Open();
       if (filetype != "image/gif" && filetype != "image/pjpeg") 
       {Response.Write( "<script language=javascript>alert('*系统演示阶段只可以选择GIF或JPG文件进行上传')</script>"); }
     else
    {
    int len=UpFile.ContentLength;
    string str_sql="insert into t_picture(picdetail,pictype,picbytesize,picname,bian_hao) "
    + " values('"+ fileByteArray +"','"+ filetype +"','"+ len +"','"+ fname +"','HQMc5-2-6')"; 
    SqlCommand com=new  SqlCommand(str_sql,con);
    com.ExecuteNonQuery();
    con.Close();
    }
    }哪里有问题、、
      

  10.   

    byte [] fileByteArray=new byte[fileLength];
      System.IO.Stream streamObject = UpFile.InputStream;
      streamObject.Read(fileByteArray, 0, fileLength);
    上面这段改一下:先去掉,然后
    fname = Path.GetFileName(UpFile.FileName);
    if (fname!="")
     {
       string str_con=System.Configuration.ConfigurationSettings.AppSettings.Get("SqlCon").ToString();
       SqlConnection con = new SqlConnection(str_con);
       con.Open();
       if (filetype != "image/gif" && filetype != "image/pjpeg") 
       {Response.Write( "<script language=javascript>alert('*系统演示阶段只可以选择GIF或JPG文件进行上传')</script>"); }
     else
    {
    ImageFormat format;
    if (filetype == "image/gif") {
       format = ImageFormat.Gif;
    } else {
       format = ImageFormat.Jpeg
    }
    MemoryStream ms = new MemoryStream();
    Image image = Image.FromFile(fname);
    image.Save(ms, format);
    byte[] fileByteArray = ms.ToArray();
    int len=UpFile.ContentLength;
    后面跟以前一样。
      

  11.   

    如果你这样做的话还要引用些什么东西。“Image image = Image.FromFile(fname);  ”
    提示Image是不明确的应用》》》》
      

  12.   

    using System.Drawing;
    using System.Drawing.Imaging;