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

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

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

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

  3.設置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.設置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);

  //保存圖片文件

 

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

·免費參觀恢復全過程

·工程師在線免費咨詢

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

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

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

息
主站蜘蛛池模板: 亚洲福利一区二区精品秒拍| 一区二区三区精品高清视频免费在线播放| 日本一区二区在线| 久久se精品一区二区| 亚洲福利视频一区二区三区| 国产亚洲福利一区二区免费看 | 免费无码一区二区| 免费看一区二区三区四区| 国偷自产av一区二区三区| 国产av一区最新精品| 久久精品无码一区二区三区日韩 | 亚洲熟女www一区二区三区| 一区二区三区视频| 国产精华液一区二区区别大吗| 日韩精品一区二区三区中文精品| 在线电影一区二区三区| 亚洲av乱码一区二区三区| 天码av无码一区二区三区四区 | 中文字幕在线精品视频入口一区| 国模极品一区二区三区| 国产电影一区二区| 久久精品国产一区| 国产婷婷色一区二区三区| 琪琪see色原网一区二区| 久久蜜桃精品一区二区三区| 精品无码av一区二区三区| 丝袜人妻一区二区三区网站| 精品女同一区二区| 国产精品亚洲一区二区在线观看| 糖心vlog精品一区二区三区| 无码一区二区三区在线| 中文字幕VA一区二区三区| 国产一区二区三区在线视頻| 亚洲一区二区精品视频| 国产天堂一区二区综合| 一区二区三区视频网站| 久久国产午夜精品一区二区三区| 色综合视频一区二区三区| av无码一区二区三区| 精品视频一区二区三区四区五区| 国产精品一区三区|