بسم الله الرحمن الرحيم
اولا قم بي انشاء فورم جديد اسمه form_save_images
عرف هذا في الاعلى
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class form_save_images
Dim ImageFile As Image
Dim ImageFilePath As String
Dim sFilePath As String
Dim imgHeight As Integer
Dim imgWidth As Integer
Dim imgType As String
Dim img As Byte()
Imports System.IO
ثاني شي اضف زر Button1 استعرض الصورة
ومربع نص Textbox1 يظهر به مسار الصوره
ثالث اضف من مربع الادوات OpenFileDialog1 على الفورم
رابع اضف مربع صورة PictureBox1 لعرض الصورة التي تم اختيارها
الكود في زر استعرض الصورة
OpenFileDialog1.Filter = "Images (*.PNG;*.BMP;*.JPG;*.GIF)|*.PNG;*.BMP;*.JPG;*.GIF|" & "All files (*.*)|*.*"
OpenFileDialog1.DefaultExt = "JPEG"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
sFilePath = OpenFileDialog1.FileName
If System.IO.File.Exists(sFilePath) = False Then
Exit Sub
Else
Me.Textbox1.Text = sFilePath
ImageFilePath = sFilePath
Try
Dim fs As FileStream = New FileStream(ImageFilePath.ToString(), FileMode.Open)
img = New Byte(fs.Length) {}
fs.Read(img, 0, fs.Length)
fs.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
ImageFile = Image.FromFile(ImageFilePath.ToString())
imgHeight = ImageFile.Height
imgWidth = ImageFile.Width
imgType = Path.GetExtension(ImageFilePath)
PictureBox1.Image = Image.FromFile(sFilePath)
End If
End If
OpenFileDialog1.Title = "Set Image File"
--------------------- sql server ------------------
قوم بي انشاء قاعدة بيانات sql server
اسمها files
فيها الجدول
images
واضف حقل اسمه img نوعه image
sql server
لايخزن الصورة يحولها الى اعداد ثنائية صفر و واحد (0,1)
Binary data
------------------------------------------
في الفورم اضف زر Button2 حفظ صورة
الكود في الزر
Dim insert_images As New SqlCommand("insert into images values (@img)", conn)
' اضافة الصورة وتحديد نوع البيانات
Dim img As New SqlParameter("@img", SqlDbType.Image)
img.Value = img
insert_images.Parameters.Add(img)
Try
conn.Open()
insert_images.ExecuteNonQuery()
conn.Close()
MsgBox("تم اضافة الصورة بنجاح")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim conn As New SqlConnection(".;database=files;integratedsecurity=true")وفي النهاية ان شاء الله يكون الشرح واضح
لا تنسانا من الدعاء