بالإضافة لمجهود الاخوه الكرام
الاكواد
1- المكتبات
كود :
Imports System.Data.OleDb
Imports System.IOكود :
Dim con As New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\dbo.mdb;Jet OLEDB:Database Password=")
Dim imgName As String
Dim sourceDirectoryName As String
Dim filyname As Stringكود :
Try
Dim dlgImage As FileDialog = New OpenFileDialog()
dlgImage.Filter = "Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif"
If dlgImage.ShowDialog() = DialogResult.OK Then
imgName = dlgImage.FileName
Dim newimg As New Bitmap(imgName)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = DirectCast(newimg, Image)
'دالة تخزن مسار الملف
sourceDirectoryName = dlgImage.FileName
'داله تقوم بتخزين اسم الملف فقط بها
filyname = My.Computer.FileSystem.GetDirectoryInfo(sourceDirectoryName).Name
t1.Text = filyname
End If
dlgImage = Nothing
Catch ae As System.ArgumentException
imgName = " "
MessageBox.Show(ae.Message.ToString())
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Tryكود :
Dim str50 As String
If con.State = ConnectionState.Closed Then
con.Open()
End If
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = con
str50 = "insert into tppicture(masar,wasf,[pic])" &
"values (@1,@2,@3)"
cmd.CommandText = str50
Dim imgParam2 As New OleDbParameter()
Dim fs2 As FileStream
fs2 = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picByte2 As Byte() = New Byte(fs2.Length - 1) {}
fs2.Read(picByte2, 0, System.Convert.ToInt32(fs2.Length))
fs2.Close()
imgParam2.OleDbType = OleDbType.Binary
imgParam2.ParameterName = "pic"
imgParam2.Value = picByte2
cmd.Parameters.AddWithValue("@1", t1.Text.Trim)
cmd.Parameters.AddWithValue("@2", t2.Text.Trim)
cmd.Parameters.AddWithValue("@3", picByte2)
cmd.ExecuteScalar()
If cmd.CommandTimeout Then
con.Close()
End If
My.Computer.FileSystem.CopyFile(sourceDirectoryName, Application.StartupPath & "\picturey\" + filyname)
MsgBox("تم إضافة الصورة بنجاح")
PictureBox1.Image = Nothingكود :
If con.State = ConnectionState.Closed Then
con.Open()
End If
Dim adapter As New OleDbDataAdapter("select * from tppicture where masar like '" & t1.Text.Trim & "' ", con)
Dim dt As New DataTable
dt.Clear()
adapter.Fill(dt)
picid.Text = dt.Rows(0).Item(0).ToString
t1.Text = dt.Rows(0).Item(1).ToString
t2.Text = dt.Rows(0).Item(2).ToString
Dim bytBLOBData() As Byte = dt.Rows(0).Item(3)
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PictureBox1.Image = Image.FromStream(stmBLOBData)كود :
If MsgBox("تاكد قبل الحذف؟", MsgBoxStyle.OkCancel, "تأكيد") = MsgBoxResult.Cancel Then
Exit Sub
End If
'Dim IDM As Integer = Val(t6.Text.Trim)
If con.State = ConnectionState.Closed Then
con.Open()
End If
Dim cmd2 As New OleDb.OleDbCommand
cmd2.Connection = con
cmd2.CommandType = CommandType.Text
cmd2.CommandText = "DELETE FROM tppicture WHERE id = " & picid.Text & ""
cmd2.ExecuteScalar()
con.Close()
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\picturey\" & t1.Text)
MsgBox("تم حذف المحدد بنجاح ")
PictureBox1.Image = Nothingاللهم صلي علي نبي (الرحمه) محمد رسول الله وبارك علي اله وصحابته والتابعين واحقن دماء امتنا واجعل بأسنا علي اعدائنا يا ارحم الراحمين
[b]امين [/b]
