سلام
چجوری عکس رو در کوئری delete و Edit قرار بدم ؟
عکس رو بە صورت باینری در دیتابیس ذخیرە کردم
عکسی از محیط برنامە
این سورس هستش
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private byte[] ImageToByteArray(System.Drawing.Image iimage)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
iimage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
return stream.ToArray();
}
}
private Image ByteArrayToImage(byte[] imageBytes)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(imageBytes))
{
Image result = Image.FromStream(stream);
return result;
}
}
private void buttonX1_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
var q = db.test_tables;
dataGridViewX1.DataSource = q;
}
private void buttonX2_Click(object sender, EventArgs e)
{
System.Data.Linq.Binary imageBinary = new System.Data.Linq.Binary(ImageToByteArray(this.pictureBox1.Image));
var db = new DataClasses1DataContext();
test_table tb = new test_table()
{
id = int.Parse(textBoxX1.Text),
name = textBoxX2.Text,
date=dateTimeInput1.Value,
img = imageBinary
};
db.test_tables.InsertOnSubmit(tb);
db.SubmitChanges();
dataGridViewX1.DataSource = db.test_tables;
}
private void buttonX3_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
int m = int.Parse(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
var QEdit = db.test_tables.Where(c => c.id == m).Single();
QEdit.name = textBoxX2.Text;
QEdit.date = dateTimeInput1.Value;
db.SubmitChanges();
dataGridViewX1.DataSource = db.test_tables;
}
private void buttonX4_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
int m = int.Parse(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
var QDel = db.test_tables.Where(c => c.id == m);
if (QDel.Count() != 0) {
db.test_tables.DeleteOnSubmit(QDel.Single());
db.SubmitChanges();
dataGridViewX1.DataSource = db.test_tables;
}
}
private void buttonX5_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
test_table tb1 = new test_table();
var Qsearch = db.test_tables.Where(c => c.name.Contains(textBoxX3.Text));
if (Qsearch.Count()==0)
{
MessageBox.Show("not found");
}
else {
this.pictureBox1.Image = ByteArrayToImage(Qsearch.First().img.ToArray());
dataGridViewX1.DataSource = Qsearch;
}
}
private void browse_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.PNG)|*.png|All Files (*.*)|(*.*)";
if (dlg.ShowDialog() == DialogResult.OK)
{
string picpath = dlg.FileName.ToString();
txt_ipath.Text = picpath;
pictureBox1.ImageLocation = picpath;
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void pictureBox2_Click(object sender, EventArgs e)
{
}
private void buttonX6_Click(object sender, EventArgs e)
{
}
private void pictureBox2_Click_1(object sender, EventArgs e)
{
if (pictureBox1.Tag != null)
{
System.Diagnostics.Process imageViewerProcess = new System.Diagnostics.Process();
imageViewerProcess.StartInfo.CreateNoWindow = false;
imageViewerProcess.StartInfo.FileName = "rundll32.exe";
imageViewerProcess.StartInfo.Arguments =
@"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen "
+ pictureBox1.Tag.ToString();
imageViewerProcess.Start();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.Opacity = 1;
for (int i = 0; i < 100; i++)
{
this.Opacity -= 0.01;
Application.DoEvents();
System.Threading.Thread.Sleep(10);
}
}
}
}
اینم سورس کوئری edit
private void buttonX3_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
int m = int.Parse(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
var QEdit = db.test_tables.Where(c => c.id == m).Single();
QEdit.name = textBoxX2.Text;
QEdit.date = dateTimeInput1.Value;
db.SubmitChanges();
dataGridViewX1.DataSource = db.test_tables;
}
اینم سورس کد کوئری Delete
private void buttonX4_Click(object sender, EventArgs e)
{
var db = new DataClasses1DataContext();
int m = int.Parse(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
var QDel = db.test_tables.Where(c => c.id == m);
if (QDel.Count() != 0) {
db.test_tables.DeleteOnSubmit(QDel.Single());
db.SubmitChanges();
dataGridViewX1.DataSource = db.test_tables;
}