PDA

View Full Version : سوال: اجرا نشدن برنامه ی ذخیره عکس



nasimplus
شنبه 17 مرداد 1394, 10:44 صبح
سلام
این کد رو قبلا میتونستم اجرا کنم اما الان اجرا نمیشه. چرا؟



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


using System.IO;
using System.Data.SqlClient;


namespace SavePhoto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


public byte[] ReadFileToByte()
{
OpenFileDialog Op = new OpenFileDialog();
if (Op.ShowDialog() == DialogResult.OK)
{
FileStream FS = new FileStream(Op.FileName, FileMode.Open);
Byte[] b = new byte[FS.Length];
FS.Read(b, 0, b.Length);
return b;
}
return null;
}


private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(" Data Source = . ; Initial Catalog = DBFile ; Integrated Security = True ");
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = sqlcon;
SqlCmd.CommandText = " Insert into TableFile values(@File) ";
byte[] b = ReadFileToByte();
SqlCmd.Parameters.AddWithValue("@File", b);
sqlcon.Open();
SqlCmd.ExecuteNonQuery();
sqlcon.Close();
}


private void Form1_Load(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(" Data Source = . ; Initial Catalog = DBFile ; Integrated Security = True ");
SqlDataAdapter DA = new SqlDataAdapter(" Select * from TableFile ", sqlcon);
DataTable DT = new DataTable();
DA.Fill(DT);
dataGridView1.DataSource = DT;
}


private void button2_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection(" Data Source = . ; Initial Catalog = DBFile ; Integrated Security = True ");
SqlDataAdapter DA = new SqlDataAdapter(" Select * from TableFile where ID = " + textBox1.Text, sqlcon);
DataTable DT = new DataTable();
DA.Fill(DT);
byte[] b = (byte[])DT.Rows[0][1];
MemoryStream MS = new MemoryStream(b);
pictureBox1.Image = Image.FromStream(MS);
}
}
}


134020
134021

عجیبه که توی دیتاگرید ویو موقع لود فرم ، جدول رو نشون نمیده!!
چه کار کنم؟