即時工作在項目做文件管理,我剛剛完成代碼上傳文件到我的數據庫(.mdf)表,但我不知道如何下載文件回來到我的文件夾(或其他任何地方)。 我看到人們從ASP.Net或OR Web數據庫下載,但我希望有人能告訴我如何從mdf數據庫下載它。如何從mdf數據庫中下載文件c#
private void find_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string Path = dlg.FileName.ToString();
PathBox.Text = Path;
PicBox.location = Path;
}
}
private void save_Click(object sender, eventargs e)
{
byte[] Doc = null;
Filestream fs = new FileStream(this.PathBox.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Doc = br.ReadBytes((int)fs.Length);
string DS = "datasource = localDB ......";
string Insertcmd = "insert into ......";
MySqlConnection conn = new MySqlConnection(DS);
MySqlCommand cmd = new MySqlCommand(Insertcmd, conn);
MySqlDataReader msdr;
try
{
conn.Open();
cmd.Parameter.Add(new MySqlParameter("@Document", Doc));
msdr = cmd.ExecuteReader();
MessageBox.Show("file saved");
While (msdr.Read())
{
}
catch (Exception ex)
{
}
}
有人可以給我一個代碼,可以從.mdf數據庫下載嗎?甚至任何暗示將是非常有益
感謝
從數據庫中選擇文件並將字節數組寫入磁盤,如下所示:http://stackoverflow.com/questions/381508/can-a-byte-array-be-written-to-a-file- in-c搜索'將字節數組寫入磁盤'。 – GrandMasterFlush
@GrandMasterFlush非常感謝你,這真的有很大的幫助:) – UnseenRoad
@GrandMasterFlush嗨,我有一個問題,你可以請檢查此鏈接:http://stackoverflow.com/questions/32939079/value-cannot-be- null-parameter-name-bytes-suggestion-please – UnseenRoad