導航:首頁 > 版本升級 > 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二進制保存文件相關的資料

熱點內容
word2003精簡版下載 瀏覽:703
微博跳轉appstore 瀏覽:537
打開文件時許可權a代表什麼 瀏覽:155
昆侖通態導出數據文件名 瀏覽:338
手機遷移數據為什麼需要重新登錄 瀏覽:958
錄入資料庫的圖片如何更改 瀏覽:132
怎樣獲取郵箱帳號和密碼 瀏覽:809
怎麼通過js實現回到指定頁面 瀏覽:140
如何用網路簽字 瀏覽:552
三星電視拆機教程 瀏覽:19
創維怎麼連接網路 瀏覽:868
2007版word繪圖在哪裡 瀏覽:311
可以拍車牌的app是什麼 瀏覽:508
文件加個井字型大小什麼意思 瀏覽:155
怎麼刪除多重網路 瀏覽:999
求生之路2區域網聯機工具 瀏覽:827
說明文件結尾用什麼詞 瀏覽:578
發送的文件名變數字 瀏覽:778
檔案資料庫管理 瀏覽:992
微信acl是金融傳銷嗎 瀏覽:620

友情鏈接