導航:首頁 > 版本升級 > sql二進制保存文件

sql二進制保存文件

發布時間:2023-08-06 08:34:26

⑴ 如何實現將文件以二進制形式存放到資料庫

這個很簡單的,這要把表單
這樣設置一下,表單裡面的數據就是以二進制的形式傳到資料庫的,至於怎麼傳到資料庫,這個就不用說吧,一個SQL插入語句就行了的,。

⑵ sqlserver2008資料庫存入和讀取二進制文件數據代碼 文件包括pdf文檔,.Docx .Excel .Zip .Rar等. 該如何實

將"數據類型"設置為"image"就行了,意思為二進制文件,不管什麼文件都可以保存的。

⑶ 怎樣才能把文本文件以二進制流的方式存進資料庫

用文件流的方式,把從文件中讀出的數據轉換成二進制,從資料庫中讀出就是反方向的:** void button1_Click(object sender, EventArgs e){byte[] buffer;buffer = File.ReadAllBytes(\"readme.doc\"); //讀取文件內容//創建連接SqlConnection connect = new SqlConnection(@\"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BSPlatform2008;Data Source=.\\SqlExpress\");SqlCommand cmd = connect.CreateCommand();cmd.CommandText = \"INSERT INTO Tmp (FileContent) VALUES (@FileContent)\"; //FileContent欄位是Image類型cmd.Parameters.Add(\"@FileContent\", SqlDbType.Image);cmd.Parameters[\"@FileContent\"].Value = buffer; //接受byte[]類型的值connect.Open();cmd.ExecuteNonQuery();connect.Close();} 查看更多答案>>

⑷ SQL資料庫 二進制圖片如何導出成文件

SQL資料庫 二進制圖片如何導出成文件
1.將圖片以二進制存入資料庫
//保存圖片到資料庫
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);
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='11' ", 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控制項顯示從資料庫中讀出的二進制圖片

閱讀全文

與sql二進制保存文件相關的資料

熱點內容
存電腦桌面的文件第二天沒有了 瀏覽:574
js算兩個時間差的天數 瀏覽:445
vb編程奇偶數怎麼編 瀏覽:298
微信怎麼發電子版文件全過程 瀏覽:510
投標文件和商務條款有什麼區別 瀏覽:851
資料庫資源量在線統計系統 瀏覽:805
jsp圖片播放 瀏覽:632
如何編程十字槽 瀏覽:865
6s網路設置會怎麼樣 瀏覽:913
桌面文件的c盤地址 瀏覽:799
法星文件夾 瀏覽:903
單片機無源蜂鳴器程序 瀏覽:311
win10文件怎麼轉區 瀏覽:588
換機wifi密碼備份 瀏覽:428
割四方孔怎麼編程 瀏覽:120
山南淘寶網站怎麼設計和運營 瀏覽:607
怎麼把桌面的文件導出來 瀏覽:902
note3智能皮套升級 瀏覽:4
安卓和web哪個工資高 瀏覽:781
如何知道網站的真假 瀏覽:748

友情鏈接