激情五月天婷婷,亚洲愉拍一区二区三区,日韩视频一区,a√天堂中文官网8

<ul id="buwfs"><strike id="buwfs"><strong id="buwfs"></strong></strike></ul>
    <output id="buwfs"></output>
  • <dfn id="buwfs"><source id="buwfs"></source></dfn>
      <dfn id="buwfs"><td id="buwfs"></td></dfn>
      <div id="buwfs"><small id="buwfs"></small></div>
      <dfn id="buwfs"><source id="buwfs"></source></dfn>
      1. <dfn id="buwfs"><td id="buwfs"></td></dfn>
        始創(chuàng)于2000年 股票代碼:831685
        咨詢熱線:0371-60135900 注冊有禮 登錄
        • 掛牌上市企業(yè)
        • 60秒人工響應(yīng)
        • 99.99%連通率
        • 7*24h人工
        • 故障100倍補償
        全部產(chǎn)品
        您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

        C#對Oracle數(shù)據(jù)庫中圖片的處理

        發(fā)布時間:  2012/8/22 17:10:30

        由于Oracle課程設(shè)計中涉及到圖片的處理,測試了好長的時間和查閱了很多的資料,終于把這個問題解決了,在這和大家分享一下:

        一、圖片保存到數(shù)據(jù)庫

        Oracle中一般保存圖片的類型為blob,一般的步驟為:

        1,首先把圖片轉(zhuǎn)化為二進制(byte[])

            FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
        -
         

                        byte[] buffByte = new byte[fs.Length];
                        fs.Read(buffByte, 0, Convert.ToInt32(fs.Length));
                        fs.Close();

        2,把二進制保存到Oracle數(shù)據(jù)庫

             string strconn = "data source = oem;user id= exam; password=exam;persist security info=false;";
                        OracleConnection conn = new OracleConnection(strconn);
                        conn.Open();
                        OracleCommand comm = new OracleCommand("addUser", conn);//存儲過程adduser
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Parameters.Add("i_name", OracleType.VarChar, 50);
                        comm.Parameters.Add("i_pic", OracleType.Blob);
                        //comm.Parameters.Add("i_result", OracleType.Int32);
                        comm.Parameters[0].Value = this.textBox2.Text;
                        comm.Parameters[1].Value = buffByte;//這個為圖片的二進制形式
                        //comm.Parameters[2].Direction = ParameterDirection.Output;
                        comm.ExecuteNonQuery();

            conn.Close();

        二、讀取Oracle數(shù)據(jù)庫轉(zhuǎn)化為圖片www.linuxidc.com

        步驟:

        1、讀出二進制

         string strconn = "data source = oem;user id= exam; password=exam;persist security info=false;";
                    OracleConnection conn = new OracleConnection(strconn);
                    conn.Open();
                    OracleCommand comm = new OracleCommand("selectUser", conn);
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.Add("flag", OracleType.Int32);
                    comm.Parameters.Add("i_name", OracleType.VarChar, 50);
                    comm.Parameters.Add("cur_out", OracleType.Cursor);
                    comm.Parameters[0].Value = 2;
                    comm.Parameters[1].Value = this.comboBox1.SelectedValue.ToString();
                    comm.Parameters[2].Direction = ParameterDirection.Output;
                    OracleDataAdapter da = new OracleDataAdapter(comm);
                    DataSet ds = new DataSet();
                    da.Fill(ds);

            conn.close();

        2、轉(zhuǎn)化為圖片

        if (ds.Tables[0].Rows.Count > 0)
                    {
                        MemoryStream buf = new MemoryStream();
                        byte[] blob = (byte[])ds.Tables[0].Rows[0]["pic"];//
                        buf.Write(blob, 0, blob.Length);
                        Image image = Image.FromStream(buf);
                        pictureBox2.Image = image;
                    }

        涉及到的存儲過程

         //create or replace procedure addUser
                        //(i_name in U_INFO.NAME%type,
                        // i_pic  in u_info.pic%type

                        // )
                        // is
                        // begin
                        //   insert into U_INFO(name,pic) values(i_name,i_pic);
                        // end adduser;

         

        //create or replace procedure selectUser
                    //(flag in int,
                    // i_name  in u_info.name%type,
                    // cur_out  out  sys_refcursor
                    // )
                    // is
                    // begin
                    //  if flag=1 then
                    //     open cur_out for
                    //      select name from U_Info;
                    //  end if;
                    //  if flag=2 then
                    //     open cur_out for
                    //      select * from U_Info where name=i_name;
                    //  end if;
                    // end selectUser;

        注:在此遇見的問題

         Image.FromStream(buf);這塊報參數(shù)無效

        可能的原因:

        1,圖片轉(zhuǎn)化為二進制是出現(xiàn)問題,導(dǎo)致讀取的二進制不能轉(zhuǎn)化為圖片,所以報參數(shù)無效

        2,讀取時轉(zhuǎn)化出錯,可能byte長度不夠,導(dǎo)致不完整,報參數(shù)無效


        本文出自:億恩科技【mszdt.com】

        服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

      2. 您可能在找
      3. 億恩北京公司:
      4. 經(jīng)營性ICP/ISP證:京B2-20150015
      5. 億恩鄭州公司:
      6. 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
      7. 億恩南昌公司:
      8. 經(jīng)營性ICP/ISP證:贛B2-20080012
      9. 服務(wù)器/云主機 24小時售后服務(wù)電話:0371-60135900
      10. 虛擬主機/智能建站 24小時售后服務(wù)電話:0371-60135900
      11. 專注服務(wù)器托管17年
        掃掃關(guān)注-微信公眾號
        0371-60135900
        Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號
          0
         
         
         
         

        0371-60135900
        7*24小時客服服務(wù)熱線