哈爾濱海月數(shù)據(jù)恢復(fù),技術(shù)亞洲領(lǐng)先 設(shè)為首頁加入收藏RSS訂閱
中國區(qū):哈爾濱(總部)鄭州福建深圳沈陽合肥大連包頭淄博上海廣州
    南京杭州嘉興武漢濟南青島新疆太原
亞太區(qū):印度韓國泰國新加坡馬來西亞澳大利亞
Windows
數(shù)據(jù)庫中圖片的二進制存儲和顯示

  與圖片的二進制數(shù)據(jù)庫存儲和顯示

  1.將圖片以二進制存入數(shù)據(jù)庫

  2.讀取二進制圖片在頁面顯示

  3.設(shè)置Image控件顯示從數(shù)據(jù)庫中讀出的二進制圖片

  4.GridView中ImageField以URL方式顯示圖片

  5.GridView顯示讀出的二進制圖片

  ====================

  1.將圖片以二進制存入數(shù)據(jù)庫

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

  protected void Button1_Click(object sender, EventArgs e)

  {

  //圖片路徑

  string strPath = "~/photo/03.JPG";

  string strPhotoPath = Server.MapPath(strPath);

  //讀取圖片

  FileStream fs = new System.IO.FileStream(strPhotoPath, FileMode.Open, FileAccess.Read);

  BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));

  bw.Write(photo);

  bw.Close();

  //顯示圖片

  tmp_Image.ImageUrl = strPath;

  }

  }

  BinaryReader br = new BinaryReader(fs);

  byte[] photo = br.ReadBytes((int)fs.Length);

  br.Close();

  fs.Close();

  //存入

  SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

  string strComm = " INSERT INTO personPhoto(personName, personPhotoPath, personPhoto) ";

  strComm += " VALUES('wangwu', '" + strPath + "', @photoBinary )";

  SqlCommand myComm = new SqlCommand(strComm, myConn);

  myComm.Parameters.Add("@photoBinary", SqlDbType.Binary,photo.Length);

  myComm.Parameters["@photoBinary"].Value = photo;

  myConn.Open();

  myComm.ExecuteNonQuery();

  myConn.Close();

  }

  2.讀取二進制圖片在頁面顯示

  //讀取圖片

  SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

  string strComm = " SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ";

  SqlCommand myComm = new SqlCommand(strComm, myConn);

  myConn.Open();

  SqlDataReader dr = myComm.ExecuteReader();

  while (dr.Read())

  {

  byte[] photo = (byte[])dr["personPhoto"];

  this.Response.BinaryWrite(photo);

  }

  dr.Close();

  myConn.Close();

  或

  SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

  SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ", myConn);

  DataSet myds = new DataSet();

  myConn.Open();

  myda.Fill(myds);

  myConn.Close();

  byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];

  this.Response.BinaryWrite(photo);

  3.設(shè)置Image控件顯示從數(shù)據(jù)庫中讀出的二進制圖片

  ---------------------------------------------

  SqlConnection myConn = new SqlConnection("Data Source=192.168.0.36;Initial Catalog=TestDB;User ID=sa;Password=sa");

  SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ", myConn);

  DataSet myds = new DataSet();

  myConn.Open();

  myda.Fill(myds);

  myConn.Close();

  byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];

  //圖片路徑

  string strPath = "~/photo/wangwu.JPG";

  string strPhotoPath = Server.MapPath(strPath);

  //保存圖片文件

  BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath,FileMode.OpenOrCreate));

  bw.Write(photo);

  bw.Close();

  顯示圖片

  this.Image1.ImageUrl = strPath;

  //4.GridView中ImageField以URL方式顯示圖片

  ----------------------------

  

  

  

  

  HeaderText="圖片">

  

  

  

  后臺直接綁定即可

  5.GridView顯示讀出的二進制圖片

  //樣板列

  

  

  

  

  HeaderText="圖片">

  

  

  

  

  

  

  

  

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

  {

  if (e.Row.RowIndex < 0)

  return;

  // System.ComponentModel.Container

  string strPersonName = (string)DataBinder.Eval(e.Row.DataItem, "personName");

  Image tmp_Image = (Image)e.Row.Cells[2].FindControl("Image1");

  if (!System.Convert.IsDBNull(DataBinder.Eval(e.Row.DataItem, "personPhoto")))

  {

  //

  byte[] photo = (byte[])DataBinder.Eval(e.Row.DataItem, "personPhoto");

  //圖片路徑

  string strPath = "~/photo/" + strPersonName.Trim() + ".JPG";

  string strPhotoPath = Server.MapPath(strPath);

  //保存圖片文件

 

 
客戶服務(wù) +more
上門服務(wù)
服務(wù)承諾
異地恢復(fù)
收費標準
付款方式
疑難解答
服務(wù)特色 +more
·免費檢測
·免費提供3天備份
·專業(yè)工程師提供服務(wù)
·免費清潔送修的介質(zhì)
·數(shù)據(jù)恢復(fù)前報價,客戶確認后工程師開始數(shù)據(jù)恢復(fù)
·數(shù)據(jù)恢復(fù)不成功不收費
·與客戶簽訂保密協(xié)議,對客戶的數(shù)
 據(jù)嚴格保密,整個恢復(fù)過程不會對
 客戶的原盤有任何的寫操作,以確
 保原盤的數(shù)據(jù)完全

·免費參觀恢復(fù)全過程

·工程師在線免費咨詢

·專業(yè)工程師提供服務(wù)
服務(wù)器數(shù)據(jù)恢復(fù) 點擊這里給我發(fā)消

息
數(shù)據(jù)庫修復(fù)
點擊這里給我發(fā)

消息
硬盤數(shù)據(jù)恢復(fù)
點擊這里給我發(fā)消

息
主站蜘蛛池模板: 偷拍激情视频一区二区三区| 久久精品一区二区东京热| 精彩视频一区二区| 欧美亚洲精品一区二区| 国产一区二区好的精华液| 无码国产精品一区二区免费模式 | 琪琪see色原网一区二区| 国产高清视频一区二区| 国产免费私拍一区二区三区| 国产一区高清视频| 精品国产香蕉伊思人在线在线亚洲一区二区| 怡红院AV一区二区三区| 亚洲国产精品一区二区第一页免| 国产一在线精品一区在线观看| 天海翼一区二区三区高清视频| 久久久av波多野一区二区| 国产精品毛片VA一区二区三区| 亚洲国产一区国产亚洲| 亚洲视频一区二区三区| 欧美激情一区二区三区成人| 日本免费一区二区三区最新vr| 波多野结衣一区二区三区88| 精品视频一区在线观看| 制服中文字幕一区二区 | 一区二区三区中文字幕| 国产天堂一区二区综合| 久久精品视频一区| 无码中文字幕一区二区三区| 精品在线视频一区| 国产综合一区二区| 亚洲国产欧美国产综合一区 | 久久精品一区二区影院| 久久se精品一区二区| 中文字幕无线码一区二区| 一区二区精品视频| 日韩一区二区在线观看视频| 激情久久av一区av二区av三区| 国产免费播放一区二区| 97一区二区三区四区久久 | 中文字幕乱码亚洲精品一区| 日本一区二区三区在线网|