當前位置:首頁 » 操作系統 » 文件保存在資料庫

文件保存在資料庫

發布時間: 2022-08-04 15:03:26

㈠ 請教如何將文件存儲資料庫

將文件保存到資料庫中,實際上是將文件轉換成二進制流後,將二進制流保存到資料庫相應的欄位中。在sql Server中該欄位的數據類型是Image,在Access中該欄位的數據類型是OLE對象。 //保存文件到SQL Server資料庫中 FileInfo fi=new FileInfo(fileName); FileStream fs=fi.OpenRead(); byte[] bytes=new byte[fs.Length]; fs.Read(bytes,0,Convert.ToInt32(fs.Length)); SqlCommand cm=new SqlCommand(); cm.Connection=cn; cm.CommandType=CommandType.Text; if(cn.State==0) cn.Open(); cm.CommandText="insert into "+tableName+"("+fieldName+") values(@file)"; SqlParameter spFile=new SqlParameter("@file",SqlDbType.Image); spFile.Value=bytes; cm.Parameters.Add(spFile); cm.ExecuteNonQuery() //保存文件到Access資料庫中 FileInfo fi=new FileInfo(fileName); FileStream fs=fi.OpenRead(); byte[] bytes=new byte[fs.Length]; fs.Read(bytes,0,Convert.ToInt32(fs.Length)); OleDbCommand cm=new OleDbCommand();

㈡ 怎樣把文本文檔里存儲的數據存到資料庫

將帶有格式的文本保存到資料庫中的方法/步驟:
1、在jsp中,頁面的帶有格式的文本內容外面用一個大的標簽,給定表簽名。
2、頁面做提交的時候用上面的表簽名點innerHTML的方式來獲取頁面帶有標簽和樣式的內容。
3、將上面取得的內容作為一個字元串保存到資料庫即可,下次把資料庫里的內容直接輸出到頁面就可以了。
對於要輸出到word里保存樣式的方法也是類似的,只是需要去看一下word解析文本的方式與jsp有何區別,在輸出到word的時候做一下變換即可。

㈢ 視頻文件能保存在資料庫中嗎怎樣設置保存呢

文件一般不會直接存資料庫吧。。。
可以考慮換個思路,文件存在項目下的一個文件夾目錄中,資料庫里保存那個文件路徑就好,讀取的時候就查詢資料庫里的路徑在通過查找文件路徑讀取文件

㈣ 如何將視頻文件存入資料庫

視頻文件不用直接保存到資料庫中的,一般的做法是,將視頻文件所在的路徑保存到資料庫中,然後通過程序調用該路徑的文件。

㈤ delphi7:如何將文件保存到sql資料庫不是圖形文件

將文件保存到sql一般來說有兩種方式
1、是只保存路徑,文件放到一個可訪問的公用地
2、是保存文件到資料庫,要以二進制方式讀寫,資料庫欄位設置為binnary
第一種方式速度快,但要布置伺服器,第二種方式省事,但效率低!
將文件保存到資料庫,你可以到網上找個二進制讀寫的例子,不同的是把讀取結果保存到數組中,在保存時你只需要把數組的內容存到SQL中即可

㈥ 你好,請問如何把電腦里的文件如何保存在資料庫中

  1. 把文件梳理出來,存入資料庫的大對象欄位

  2. 行程腳本執行,這個估計非常慢

㈦ 如何把文件存放到資料庫中

發給你一個上傳圖片並把它存入資料庫的例子。
1.前台<table cellpadding="0" cellspacing="0"
<tr<td colspan="2"</td</tr<tr<td<asp:Label ID="Label1" runat="server" Font-Size="9pt" Text="選擇文件"</asp:Label</td
<td align="left"<asp:FileUpload ID="FileUpload1" runat="server" Font-Size="9pt" /</td</tr<tr<td</td
<td align="left"
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="保存"/</td</tr<tr<td</td
<td align="left"
<asp:Label ID="Label3" runat="server" Font-Size="9pt" Width="216px"</asp:Label</td</tr</table
2.後台using System.IO;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page{protected void Button1_Click(object sender, EventArgs e){try{if (this.FileUpload1.PostedFile.FileName != ""){string ImgPath = FileUpload1.PostedFile.FileName;
string ImgName = ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1);
string ImgExtend = ImgPath.Substring(ImgPath.LastIndexOf(".") + 1);
int FileLen = this.FileUpload1.PostedFile.ContentLength;
Byte[] FileData = new Byte[FileLen];
HttpPostedFile hp = FileUpload1.PostedFile;
Stream sr = hp.InputStream;
sr.Read(FileData, 0, FileLen);
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=db_07");
con.Open();
SqlCommand com = new SqlCommand("INSERT INTO tb_08 (name) VALUES (@imgdata)", con);
com.Parameters.Add("@imgdata", SqlDbType.Image);
com.Parameters["@imgdata"].Value = FileData;
Label3.Text = "保存成功!";}else{Label3.Text = "請選擇文件!";}}catch (Exception error){Label3.Text = "處理失敗!原因為:" + error.ToString();}}}

㈧ 如何把文件存放在mysql資料庫中

在my.ini文件里可以設定數據文件的存放路徑將其從原來的目錄移動到指定的位置;修改配置文件my.ini,也就是把socket和data的目錄改到你移到的位置

㈨ 將word文檔保存到資料庫中

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace ConsoleApplication2
{
class Program
{
//把文件寫入資料庫
public void add(string pathName)
{
FileStream fs = new FileStream(pathName, FileMode.Open, FileAccess.Read);
byte[] buffByte = new byte[fs.Length];
fs.Read(buffByte, 0, (int)fs.Length);
fs.Close();
fs = null;
SqlConnection conn = new SqlConnection(@"data source=test;uid=sa;pwd=test;database=test");
string sqlstr = @"Insert into table1(doc) values(@img)";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstr;
cmd.Connection = conn;
cmd.Parameters.Add("@img", System.Data.SqlDbType.Image);
cmd.Parameters[0].Value = buffByte;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
buffByte = null;

}
//從資料庫讀出文件
public void save(string fileName)
{
SqlConnection conn = new SqlConnection(@"data source=test;uid=sa;pwd=test;database=test");
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 doc from table1", conn);
SqlDataReader reader = cmd.ExecuteReader();
byte[] buffByte = null;
if (reader.Read())
{
buffByte = (byte[])reader[0];
}
reader.Close();
conn.Close();
FileStream fs;
FileInfo fi = new FileInfo(fileName);
fs = fi.OpenWrite();
fs.Write(buffByte, 0, buffByte.Length);
fs.Close();
}
static void Main(string[] args)
{
Program p = new Program();
p.add(@"C:\test.doc");
p.save(@"C:\test1.doc");
}
}
}

熱點內容
做腳本掛 發布:2024-05-02 19:09:14 瀏覽:931
打王者開最高配置哪個手機好 發布:2024-05-02 19:08:31 瀏覽:351
python字典使用 發布:2024-05-02 19:01:14 瀏覽:134
我的世界伺服器聯機ip 發布:2024-05-02 18:50:39 瀏覽:619
steam密碼從哪裡看 發布:2024-05-02 18:50:00 瀏覽:629
convertlinux 發布:2024-05-02 18:20:00 瀏覽:705
zxingandroid簡化 發布:2024-05-02 17:47:53 瀏覽:189
貴州銀行卡查詢密碼是什麼 發布:2024-05-02 17:47:17 瀏覽:119
颶風演算法沒用 發布:2024-05-02 17:41:41 瀏覽:350
android鈴聲設置 發布:2024-05-02 17:40:01 瀏覽:485