[QUOTE] byte[] ReadFile(string sPath)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
return data;
}[/QUOTE]
و
[QUOTE] private void bpic_Click_1(object sender, EventArgs e)
{
OpenFileDialog fd = new OpenFileDialog();
fd.InitialDirectory = Application.StartupPath;
fd.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif";
fd.FilterIndex = 1;
fd.ShowReadOnly = true;
fd.Title = " Open Window Select Image ... ";
fd.ShowHelp = true;
if (fd.ShowDialog() == DialogResult.OK)
{
picbox1.ImageLocation = fd.FileName;
label10.Text = fd.FileName;
}
}[/QUOTE]
و
[QUOTE] private void bins_Click(object sender, EventArgs e)
{
try
{
if (boxname.Text == "")
{
MessageBox.Show(" Filed Name is Empty... ", "Dont Save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else if (boxiddaneshjo.Text == "")
{
MessageBox.Show(" Filed Id is Empty... ", "Dont Save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else if (label10.Text == "-i-m-a-g-e-")
{
MessageBox.Show(" Picture box is Empty... ", "Dont Save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else
{
SqlCommand cm = new SqlCommand();
byte[] imageData = ReadFile(label10.Text);
string insertandupdate = string.Format("INSERT INTO daneshjo (name,id,year,month,reshte,Grayesh,maghtetahsili,nahvepaziresh,OriginalPath,ImageData) VALUES " +
"(@name,@id,@year,@month,@reshte,@Grayesh,@maghtetahsili,@nahvepaziresh,@OriginalPath,@ImageData)");
cm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = boxname.Text.Trim();
cm.Parameters.Add("@id", SqlDbType.NVarChar, 11).Value = boxiddaneshjo.Text.Trim();
cm.Parameters.Add("@year", SqlDbType.NVarChar, 50).Value = boxinyear.Text.Trim();
cm.Parameters.Add("@month", SqlDbType.NVarChar, 50).Value = cbomah.Text.Trim();
cm.Parameters.Add("@reshte", SqlDbType.NVarChar, 50).Value = cboreshte.Text.Trim();
cm.Parameters.Add("@Grayesh", SqlDbType.NVarChar, 50).Value = cbogaryesh.Text.Trim();
cm.Parameters.Add("@maghtetahsili", SqlDbType.NVarChar, 50).Value = cbomaghtaetahsili.Text.Trim();
cm.Parameters.Add("@nahvepaziresh", SqlDbType.NVarChar, 50).Value = cbonahvepaziresh.Text.Trim();
cm.Parameters.Add(new SqlParameter("@OriginalPath", (object)label10.Text));
cm.Parameters.Add(new SqlParameter("@ImageData", (object)imageData));
cm.Connection = con;
cm.CommandText = insertandupdate;
con.Open();
cm.ExecuteNonQuery();
MessageBox.Show("One Rows Affected Successfully...", "Save to ..", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
string Q1ForLastTxtSabtNameheyErsali = "select * from daneshjo order by id desc ";
string sotonersali = "id";
AccessToDB.readlastnumforinsert(Q1ForLastTxtSabtNameheyErsali, sotonersali, boxiddaneshjo);
boxiddaneshjo.Text = Convert.ToString(Int64.Parse( boxiddaneshjo.Text) + 1);
// boxname.Text = "";
// picbox1.Image = null;
// label10.Text = "-i-m-a-g-e-";
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
finally
{
con.Close();
}
}[/QUOTE]
و حالا لودش:
[QUOTE] byte[] ReadFile(string sPath)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
return data;
}[/QUOTE]
[QUOTE]private void bup_Click(object sender, EventArgs e)
{
try
{
byte[] imageData = ReadFile(label10.Text);
SqlCommand cmd = new SqlCommand();
string insertandupdate = string.Format("update daneshjo set name=@name,id=@id,year=@year,month=@month,reshte=@reshte,Grayesh=@Grayesh,maghtetahsili=@maghtetahsili,nahvepaziresh=@nahvepaziresh,OriginalPath=@OriginalPath,ImageData=@ImageData where id='{0}'",dataGridView1.CurrentRow.Cells[1].Value.ToString());
cmd.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = boxname.Text.Trim();
cmd.Parameters.Add("@id", SqlDbType.NVarChar, 50).Value = boxiddaneshjo.Text.Trim();
cmd.Parameters.Add("@year", SqlDbType.NVarChar, 50).Value = boxinyear.Text.Trim();
cmd.Parameters.Add("@month", SqlDbType.NVarChar, 50).Value = cbomah.Text.Trim();
cmd.Parameters.Add("@reshte", SqlDbType.NVarChar, 50).Value = cboreshte.Text.Trim();
cmd.Parameters.Add("@Grayesh", SqlDbType.NVarChar, 50).Value = cbogaryesh.Text.Trim();
cmd.Parameters.Add("@maghtetahsili", SqlDbType.NVarChar, 50).Value = cbomaghtaetahsili.Text.Trim();
cmd.Parameters.Add("@nahvepaziresh", SqlDbType.NVarChar, 50).Value = cbonahvepaziresh.Text.Trim();
cmd.Parameters.Add(new SqlParameter("@OriginalPath", (object)label10.Text));
cmd.Parameters.Add(new SqlParameter("@ImageData", (object)imageData));
cmd.Connection = con;
cmd.CommandText = insertandupdate;
con.Open();
cmd.ExecuteNonQuery();
string Q1ForLastTxtSabtNameheyErsali = "select id from daneshjo order by id desc ";
string sotonersali = "id";
AccessToDB.readlastnumforinsert(Q1ForLastTxtSabtNameheyErsali, sotonersali, boxiddaneshjo);
boxiddaneshjo.Text = Convert.ToString(Int64.Parse( boxiddaneshjo.Text )+ 1);
MessageBox.Show("One Rows Affected Successfully...", "Update to ..", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
//showGrid();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
finally { con.Close(); }
}[/QUOTE]
[QUOTE]private void SelcetValue_For_Grid()
{
try
{
boxname.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim();
boxiddaneshjo.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString().Trim();
boxinyear.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString().Trim();
cbomah.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString().Trim();
cboreshte.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString().Trim();
cbogaryesh.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString().Trim();
cbomaghtaetahsili.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString().Trim();
cbonahvepaziresh.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString().Trim();
label10.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString().Trim();
picbox1.Image = Image.FromFile(dataGridView1.CurrentRow.Cells[8].Value.ToString().Trim());
}
catch (Exception ex) { MessageBox.Show(ex.Message); picbox1.Image = null; }
}[/QUOTE]