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

熱點內容
win7無法打開隱藏文件 瀏覽:757
怎樣把壓縮文件變成空白文件 瀏覽:516
wokrNC和UG編程哪個好 瀏覽:487
愛奇藝隨刻文件名 瀏覽:40
wps是怎麼壓縮文件 瀏覽:986
dos配置文件名 瀏覽:582
java軟體工程師做什麼 瀏覽:897
3dmax導出ive文件 瀏覽:464
數據重復性好是什麼意思 瀏覽:166
如何查找電腦文件使用歷史記錄 瀏覽:821
linux可以運行exe的文件嗎 瀏覽:935
庫幣是哪個國家的app 瀏覽:201
大智慧internet文件夾有哪些文件 瀏覽:89
編程培訓課程哪個排名好 瀏覽:124
我的cad怎麼沒顯示文件選項卡 瀏覽:952
命令行當前是哪個資料庫 瀏覽:588
為什麼appstore打開空白 瀏覽:574
選貨車軟體什麼app最好 瀏覽:577
psv仙境傳說ace如何降級版本 瀏覽:460
杭州哪裡學少兒編程比較好 瀏覽:642

友情鏈接