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

熱點內容
上海房主發布租房哪個網站好 瀏覽:311
郊區用什麼網路 瀏覽:269
樂寫app如何發作品屏蔽人 瀏覽:584
linux中文件壓縮與打包 瀏覽:34
拷貝文件夾到指定目錄 瀏覽:103
win10打不來金橙子軟體下載 瀏覽:789
virtuagirlhd安卓版 瀏覽:39
word上面插入pdf文件 瀏覽:568
javac內存管理 瀏覽:532
秒剪APP怎麼剪掉不要的部分 瀏覽:416
宜賓有什麼拆遷文件 瀏覽:811
linuxterminator使用 瀏覽:551
ai啟動配置文件 瀏覽:664
汽車故障診斷數據採集有什麼用 瀏覽:594
手機對手機傳文件最快 瀏覽:103
文件預覽窗格圖片怎麼放大 瀏覽:699
自動編程適用於哪些情況 瀏覽:686
樂高編程課是學什麼的幼兒園 瀏覽:880
照片刪除了在哪個文件夾 瀏覽:513
電腦怎麼把文件圖片變大 瀏覽:565

友情鏈接