PDA

View Full Version : سوال: ذخیره و باز یابی فایل از دیتابیس (SqlServer)



sari-1369
شنبه 28 فروردین 1389, 17:35 عصر
سلام ، چطوری میشه یه فایل (برای مثال : Exe , Dll ) رو توی دیتابیس ذخیره و انو دوباره بازیابی کرد ؟

نوع فیلد - طریقه درج در بانک - خوندن از بانک

hero4000
شنبه 28 فروردین 1389, 17:59 عصر
دوست عزيز دقيقا مثل حالتي که يک عکس رو توي بانک ذخيره ميکنين عمل کنين

ابتدا فايل رو بخونين سپس اونرو در يک آرايه از بايت بريزيد سپس آرايه رو در بانک ذخيره کنين

براي خوندن هم دقيقا با همون Select که ميگيرين اطلاعات رو بهتون ميده

sari-1369
یک شنبه 29 فروردین 1389, 09:23 صبح
از دوستان کسی میتونه یه مثال کاربردی بزنه ؟ کارم گیر کرده

hero4000
دوشنبه 30 فروردین 1389, 09:19 صبح
If openfiledialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
filename = openfiledialog1.FileName
filebyte2 = My.Computer.FileSystem.ReadAllBytes(filename)
filebyte = My.Computer.FileSystem.ReadAllBytes(filename)
end if
command.CommandText = "insert into [names] (name,tel,mobile,fax,addres,[desc],[group],other1,other2,other3,other4,filepic,filename,pics mall) values (" & _
"@TextBox1.Text ,@TextBox2.Text ,@TextBox3.Text ,@TextBox4.Text ,@TextBox5.Text , @TextBox6.Text ,@ComboBox1.SelectedValue ,@TextBox7.Text ,@TextBox8.Text ,@TextBox9.Text ,@TextBox10.Text,@filepic,@filename,@picsmall)"
command.Parameters.Clear()
command.Parameters.Add("@TextBox1.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox1.Text
command.Parameters.Add("@TextBox2.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox2.Text
command.Parameters.Add("@TextBox3.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox3.Text
command.Parameters.Add("@TextBox4.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox4.Text
command.Parameters.Add("@TextBox5.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox5.Text
command.Parameters.Add("@TextBox6.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox6.Text
command.Parameters.Add("@ComboBox1.SelectedValue", OleDb.OleDbType.BigInt, 4).Value = ComboBox1.SelectedValue
command.Parameters.Add("@TextBox7.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox7.Text
command.Parameters.Add("@TextBox8.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox8.Text
command.Parameters.Add("@TextBox9.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox9.Text
command.Parameters.Add("@TextBox10.Text", OleDb.OleDbType.VarChar, 255).Value = TextBox10.Text
command.Parameters.Add("@filepic", OleDb.OleDbType.VarBinary, filebyte.Length).Value = filebyte
command.Parameters.Add("@filename", OleDb.OleDbType.VarChar, 50).Value = filename.Substring(Strings.InStrRev(filename, "\"), filename.Length - Strings.InStrRev(filename, "\"))
command.Parameters.Add("@picsmall", OleDb.OleDbType.VarBinary, filebyte2.Length).Value = filebyte2

command.ExecuteNonQuery()

sari-1369
دوشنبه 30 فروردین 1389, 10:39 صبح
ممنون دوست عزیز .

خب این برای درج در بانک بود ، حالا من میخوام دوباره فایلمو از بانک بخونم و به صورت یه فایل (برای مثال dll ) روی هارد ذخیره کنم .

hero4000
سه شنبه 31 فروردین 1389, 08:05 صبح
com.CommandText = "select [names].filepic from [names] where id = " & tt
filebyte = com.ExecuteScalar

Dim savefiledialog1 As New SaveFileDialog
savefiledialog1.Filter = "*." & filename.Substring(Strings.InStrRev(filename, "."), filename.Length - Strings.InStrRev(filename, ".")).ToLower() & "|*." & filename.Substring(Strings.InStrRev(filename, "."), filename.Length - Strings.InStrRev(filename, ".")).ToLower()
If savefiledialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllBytes(savefiledialo g1.FileName, filebyte, False)
End If