-
قرار دادن عكس در برنامه
با سلام
جناب someone كدهايي كه براي تبديل به byte بود را گذاشتم ولي ارور مي دهد من كدهايي كه اطلاعات را در جدولم قرار مي دهد را برايتان مي گذارم
[HTML]
private void button12_Click(object sender, EventArgs e)
{
ersalcart.dsersal.personelRow dr = this.dsersal1.personel.NewpersonelRow();
dr.fname = this.textBox15.Text;
dr.lname = this.textBox16.Text;
dr.nameoffather = this.textBox18.Text;
dr.numberofshenasname = this.textBox19.Text;
dr.numbermeli =long .Parse ( this.textBox20.Text);
dr.address = this.textBox21.Text;
dr.tel = this.textBox22.Text;
dr.numofparvande = this.textBox23.Text;
dr.kholasevaziat =this .textBox24 .Text ;
dr.pic=this.pictureBox.backgroundImage;اين قسمت را ارور مي دهد كه نمي تواند به byte تبديل كند
//DataRowView drv = (DataRowView)this.BindingContext[this.peymankarBindingSource].Current;
//int cp =(int) drv.Row["capacitypersonel"];
//cp++;
//drv.Row["capacitypersonel"] = cp;
//this.sqlDapeymankar.Update(this.dsersal1.peymankar );
dr.tahsilat_ =(int)this .comboBox7 .SelectedValue ;
dr.startofyear_ =(int)this .comboBox8 .SelectedIndex ;
dr.gruopofkhon_ =(int)this .comboBox9 .SelectedValue ;
dr.sizeofshoes_ =(int)this .comboBox10.SelectedValue ;
dr.sizeofcloths_ =(int)this .comboBox11 .SelectedValue ;
dr.yearoftahvil_ =(int)this .comboBox12 .SelectedValue ;
dr.typeofactive_ =(int)this .comboBox18 .SelectedValue ;
dr.sharhekar_ =(int)this .comboBox14 .SelectedValue ;
dr.takhasos_ =(int)this .comboBox15 .SelectedValue ;
dr.yeraofend_ =(int)this .comboBox1.SelectedValue ;
dr.typeofpersonel_ =(int)this .comboBox16.SelectedValue ;
this .textBox27 .Text = this.comboBox8.SelectedItem + this.textBox23.Text + this.comboBox7.SelectedValue;
this .textBox25 .Text = this.comboBox14.SelectedValue +" "+ this.comboBox15.SelectedValue;
// this.saveFileDialog1.FileName = " ";
/// if (this.saveFileDialog1.FileName != " ")
// this.pictureBox2.BackgroundImage.Save(saveFileDial og1.FileName);
this.dsersal1.personel .AddpersonelRow (dr);
this.sqlDapersonel .Update(this.dsersal1.personel );
MessageBox.Show("اطلاعات ثبت گرديد ");
}
[/HTML]
در اينجا من بايد چه كنم كه آن يك خط كد درست شود قابل توجه كه من نوع pic را در جدول Image گرفتم
من بايد چه كنم تا عكس در پايگاه داده ام قرار بگيرد
-
دوباره سلام.
کد:
Image image = pictureBox1.Image;
byte[] result;
try
{
MemoryStream mem = new MemoryStream();
image.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
result = mem.ToArray();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
و