الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Object reference not set to an instance of an object

بدأه كارم سامي في 21 فبراير 2014 · 6 رد · 542 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ,

يظهر خطأ عند تنفيذ هذا الكود في السطر

pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);

والخطأ هو

 

Object reference not set to an instance of an object.

 

ما الحل وشكراً

OleDbConnection JSS_cn001 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/JE_SaleStoreDB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014");
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
            byte[] rawdata = ms.GetBuffer();
            OleDbCommand Cmd = new OleDbCommand("update company_info set companyinfo_NAME = '" + textBox1.Text + "', companyinfo_BRANCHE = '" + textBox2.Text + "', companyinfo_ADDRESS = '" + textBox3.Text + "', companyinfo_TEL1 = '" + textBox4.Text + "' , companyinfo_TEL2 = '" + textBox5.Text + "' , companyinfo_TEL3 = '" + textBox6.Text + "' , companyinfo_TEL4 = '" + textBox7.Text + "' , companyinfo_EMAIL = '" + textBox8.Text + "', companyinfo_WEB = '" + textBox10.Text + "', companyinfo_FACEBOOK = '" + textBox11.Text + "', companyinfo_LOGO = @Img WHERE companyinfo_ID='1', JSS_cn001");
            JSS_cn001.Open();
            Cmd.Parameters.AddWithValue("@Img", rawdata);
            Cmd.ExecuteNonQuery();
            Cmd.Dispose();
            JSS_cn001.Close();
#2

update this line to

pictureBox1.Image.Save(ms, Imaging.ImageFormat.Jpeg);

look this link

http://stackoverflow.com/questions/15273617/c-sharp-insert-picture-into-ms-access

#3
KARIMSOFT كتب:

update this line to

pictureBox1.Image.Save(ms, Imaging.ImageFormat.Jpeg);

look this link

http://stackoverflow.com/questions/15273617/c-sharp-insert-picture-into-ms-access

 

 

 

The name 'Imaging' does not exist in the current context  

 

علماً بأن هذا الكود لادخال الصورة لـ pictureBox1

 private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog JSS_og1 = new OpenFileDialog();

            var _with1 = JSS_og1;
            JSS_og1.Title = "(Select Image) (تحديد صورة)";
            JSS_og1.Filter = "JPEG,BMP,PNG  (تحديد صورة) (Select Image) |*.jpg;*.jpeg;*.bmp;*.png";

            if (JSS_og1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                pictureBox1.Image = Image.FromFile(JSS_og1.FileName);
            }
            else
            {
                MessageBox.Show("عفواً ألغي الأمر بناء على طلبك");
                this.Focus();
            }
        }

تم تعديل هذه المشاركة بواسطة كارم سامي في 21 فبراير 2014 في 21:23

#4

مع استخدام هذا الكود ايضاُ يعطي نفس المشكلة الاولي

 pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

Object reference not set to an instance of an object.

#5

if (pictureBox1.Image!=null)pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);

VB.NET and C# Comparison

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

002.gif

=-=-=-=-=-=-=
ذو العلم يشقى فى النعيم بعلمه .:. واخو الجهالة فى الشقاوة ينعم
=-=-=-=-=-=-=
يا من بدنياه اشتغل . قد غره طول الأمل . فالموت يأتى بغتة . والقبر صندوق العمل
=-=-=-=-=-=-=
ان لم تستطع ان تجد ما تفعله فافعل ما لم تسطع ان تجده

screen_shot_2011-05-19_at_12.44.49_pm.pn

#6
SOLO.NET كتب:
 if (pictureBox1.Image!=null)pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);

 

 

 

ظهر خطـ جديد في السطر

Cmd.ExecuteNonQuery();

 

وهو

 

{"ExecuteNonQuery: Connection property has not been initialized."}

#7

شكراً لكم

تم حل المشكلة بعد تصحيح هذا الخطأ الاخر

 OleDbCommand Cmd = new OleDbCommand("update company_info set companyinfo_NAME = '" + textBox1.Text + "', companyinfo_BRANCHE = '" + textBox2.Text + "', companyinfo_ADDRESS = '" + textBox3.Text + "', companyinfo_TEL1 = '" + textBox4.Text + "' , companyinfo_TEL2 = '" + textBox5.Text + "' , companyinfo_TEL3 = '" + textBox6.Text + "' , companyinfo_TEL4 = '" + textBox7.Text + "' , companyinfo_EMAIL = '" + textBox8.Text + "', companyinfo_WEB = '" + textBox10.Text + "', companyinfo_FACEBOOK = '" + textBox11.Text + "', companyinfo_LOGO = @Img WHERE companyinfo_ID='1'", JSS_cn001);

مواضيع مشابهة