PDA

View Full Version : ذخیره تصویر در دیتابیس mdf



nassim0
یک شنبه 04 فروردین 1392, 09:46 صبح
با سلام خدمت دوستان
من یک برنامه تحت ویندوز نوشتم که توی اون از بانک اطلاعاتی با نوع dbo استفاده کردم (linq) برای اجرای برنامم توی کامپیوتر کاربر حتما باید sql نصب بشه که پیش نیاز اون هم power shell و .net 3.5 sp1 هستش مسئله بعد هم اتصال اون به بانک که خودش میشه یک داستان جدا . خواستم از mdf استفاده کنم اما نمی دونم چرا عکس رو ذخیره نمی کنه به محض اینکه دوباره بانک رو برمی گردونم روی dbo مسئله حل میشه .(من استفاده از linq رو داخل فیلم های همین سایت یاد گرفتم .توی این برنامه من نیاز دارم که حتما خود عکس رو ذخیره کنم نه آدرسش رو )لطفا راهنماییم کنید .
http://aliphoenix.persiangig.com/video/kitchen.flv

saeed31641
یک شنبه 04 فروردین 1392, 10:30 صبح
کد برنامتون بزارین تا ببینمی بعد عکس رو حتما بصورت باینری باید ذخیر کنی
http://beyondrelational.com/modules/2/blogs/117/posts/14647/how-to-save-and-retrieve-images-using-linq-to-sql-with-sql-compact.aspx
http://stackoverflow.com/questions/9696888/how-to-insert-get-images-usin-linq
http://stackoverflow.com/questions/9696888/how-to-insert-get-images-usin-linq

از این لینکها ایده بگیر و جستجو کن

Visual studio
یک شنبه 04 فروردین 1392, 21:17 عصر
تو دیتابیس، نوع فیلد رو binarymax قرار بده.
برای ذخیره تصویر تو دیتابیس هم از دستور زیر استفاده کن.
System.IO.File.ReadAllBytes(عکس)

nassim0
یک شنبه 04 فروردین 1392, 21:46 عصر
if (comboBox2.Text == "انتخاب پوشه")
{
}

else
{

Persia.SolarDate solarDate = Persia.Calendar.ConvertToPersian(DateTime.Now);
string logst = solarDate.ToString("S,T");
OpenFileDialog _op = new OpenFileDialog();
_op.Multiselect = true;
if (_op.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_files = new List<string>();
_files.AddRange(_op.FileNames);
_files.Sort();
_numberPreviewImages = _files.Count;
_currentStartImageIndex = 0;
if (_numberPreviewImages == 1)
{
_currentStartImageIndex = 0;
_currentEndImageIndex = 1;
}
else
{
_currentEndImageIndex = _currentStartImageIndex + _numberPreviewImages;
}

if (_files == null)
{
return;
}

if (this.WindowState == FormWindowState.Minimized)
{
return;
}

// Display the ProgressBar control.

pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = _numberPreviewImages;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
pBar1.Step = 1;
for (int index = 0; index < _currentEndImageIndex; index++)
{
DataClasses1DataContext search = new DataClasses1DataContext();
var q1 = from p1 in search.subgroup_tables
where p1.name == System.IO.Path.GetFileName(_files[index])
select p1;
string searchst = "";
foreach (subgroup_table f1 in q1)
searchst = f1.name;
if (searchst == System.IO.Path.GetFileName(_files[index]))
{
string message = "قبلا به ثبت رسیده است " + System.IO.Path.GetFileName(_files[index]) + "تصویر";
string caption = "خطای تشابه نام";
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult result;
result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Error);

}
else
{


DataClasses1DataContext log = new DataClasses1DataContext();
log.subgroup_tables.InsertOnSubmit(new subgroup_table { name = System.IO.Path.GetFileName(_files[index]), img = System.IO.File.ReadAllBytes(_op.FileNames[index]), date = System.IO.Path.GetFullPath(_files[index]).ToString(), groupname = comboBox2.SelectedValue.ToString(),time=logst });
log.SubmitChanges();



// Loop through all files to copy.
pBar1.PerformStep();
}
}
string message1 = "ثبت تصاویر با موفقیت انجام شد";
string caption1 = "تایید عملیات";
MessageBoxButtons buttons1 = MessageBoxButtons.OK;
DialogResult result1;
result1 = MessageBox.Show(this, message1, caption1, buttons1, MessageBoxIcon.Asterisk);
pBar1.Visible = false;
// update comboboxs
DataClasses2DataContext mach = new DataClasses2DataContext();
var q = from p in mach.group_tables
select p;
comboBox1.DataSource = q;
comboBox4.DataSource = q;
comboBox2.DataSource = q;
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "name";
comboBox4.DisplayMember = "name";
comboBox4.ValueMember = "name";
comboBox2.DisplayMember = "name";
comboBox2.ValueMember = "name";
}

nassim0
دوشنبه 05 فروردین 1392, 19:16 عصر
كد buttom برنامه رو براتون گذاشتم. مربوط به ذخيره تصوير

nassim0
چهارشنبه 07 فروردین 1392, 09:22 صبح
دوستان وقتی از mdf توی وب استفاده میکنم تصویر رو ذخیره میکنه اما وقتی توی application استفاده می کنم تصویر ذخیره نمیشه