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

كيفية عرض صوره محفوظه فى قاعدة بيانات sqlserver

مغلق
بدأه mr_boss في 28 سبتمبر 2006 · 0 رد · 342 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

لدى مشكله فى عرض صوره محفوظة فى قاعدة بيانات

الكود التالى يعمل مع قاعدة بيانات بها جدول مكون من عمودين

1- Picture من نوع Image وطوله 16

2- FileName من نوع Varchar وطوله 250

وعند التنفيذ يعرض فى picturebox

نفس الكود لا يعمل على جدول آخر فيه أربعة أعمدة

1- ID

2- Name نوعه varchar وطوله 30 ويحمل اسم الصورة

3- image نوعه Image وطوله 16

4- filename نوعه varchar وطوله 250

وعند التنفيذ بيطلع خطأ out of memory عند سطر picturbox1.backgroundimage

			SqlCommand getEmp = new SqlCommand("SELECT Picture FROM Pictures where FileName ='EG-FLAG.GIF'",sqlConnection1);

			FileStream fs;						  // Writes the BLOB to a file (*.bmp).
			BinaryWriter bw;						// Streams the BLOB to the FileStream object.
			int bufferSize = 100;				   // Size of the BLOB buffer.
			byte[] outbyte = new byte[bufferSize];  // The BLOB byte[] buffer to be filled by GetBytes.
			long retval;							// The bytes returned from GetBytes.
			long startIndex = 0;					// The starting position in the BLOB output.
			string emp_id = "";					 // The employee id to use in the file name.

			// Open the connection and read data into the DataReader.
			sqlConnection1.Open();
			SqlDataReader myReader = getEmp.ExecuteReader(CommandBehavior.SequentialAccess);

			while (myReader.Read())
			{
				// Create a file to hold the output.
				fs = new FileStream("employee" + emp_id + ".bmp",
					FileMode.OpenOrCreate, FileAccess.Write);
				bw = new BinaryWriter(fs);

				// Reset the starting byte for the new BLOB.
				startIndex = 0;

				// Read the bytes into outbyte[] and retain the number of bytes returned.
				retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);


				// Continue reading and writing while there are bytes beyond the size of the buffer.
				while (retval == bufferSize)
				{
					bw.Write(outbyte);
					bw.Flush();

					// Reposition the start index to the end of the last buffer and fill the buffer.
					startIndex += bufferSize;
					retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
				}

				// Write the remaining buffer.
				bw.Write(outbyte, 0, (int)retval);
				bw.Flush();

				// Close the output file.
				bw.Close();
				fs.Close();
				pictureBox1.BackgroundImage=Image.FromFile("employee" + emp_id + ".bmp");
			}

			// Close the reader and the connection.
			myReader.Close();
			sqlConnection1.Close();
Flag_of_Palestine.gif

هذا الموضوع مغلق.

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