كود حفظ الصورة وجده لكن لايعمل بالكامل - 0theghost0 - 08-11-14
السلام عليكم
شباب حصلت كود لحفظ الصورة داخل access 2013 لكن لم يعمل بالكامل سوف اضع لكم كود وحفظ الصورة والكود حقي لبرمجت الكودين معا لحفظ الصورة في الاكسس وبالاخير سوف اسألكم بعد الانتهاء من هذة الخطو بالخطوة الجديدة وهي قراءة البيانات مع الصورة المحفوظه لهذا الشخص .
كود جفظ الصورة :
كود :
Private Sub SaveToDB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToDB1.Click
Dim str As New MemoryStream
pic.Image.Save(str, Imaging.ImageFormat.Jpeg)
Dim buffer(CInt(str.Length - 1)) As Byte
str.Position = 0
str.Read(buffer, 0, CInt(str.Length))
Dim con As New OleDbConnection(conString)
Dim cmd As New OleDbCommand("INSERT INTO Pictures (ThePicture) VALUES (@ThePicture)", con)
cmd.CommandType = CommandType.Text
Dim prmPic As New OleDbParameter
With prmPic
.ParameterName = "@MyPicture"
.OleDbType = OleDbType.Binary
.Value = buffer
End With
cmd.Parameters.Add(prmPic)
Try
con.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("The image was saved successfully.")
pic.Image = Nothing
Catch ex As Exception
MessageBox.Show("There was a problem saving the image." & ControlChars.CrLf & ex.Message)
Finally
If con.State = ConnectionState.Open Then con.Close()
con.Dispose() : cmd.Dispose()
con = Nothing : cmd = Nothing : prmPic = Nothing
End Try
End Sub
اما هذا الكود خاص بي واريد اضافة او تعديله لي مع تعليمي مالكود الخاص بحفظ الصورة :
كود :
conn.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath() & "\Data.accdb" & ";Persist Security Info=True;Jet OLEDB:Database Password=123"
Try
conn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand("insert into Student (Student_Name,Student_CPR,Student_Birth,Student_Join,Student_Nation,Student_Sex,Student_D,Student_Place,Student_Address,Student_Sick,Student_Vairus,Student_phone,Student_Dad,Student_mom,Student_Angel,Student_jobmom,Student_jobdad,Student_Famaly,Student_Pic) values ('" & TextBox1.Text & "','" & TextBox10.Text & "','" & DateTimePicker1.Value & "','" & DateTimePicker2.Value & "','" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & ComboBox1.Text & "','" & ComboBox4.Text & "','" & TextBox2.Text & "','" & ComboBox5.Text & "','" & TextBox7.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & ComboBox6.Text & "','" & PictureBox1.Image & "')", conn)
cmd.ExecuteNonQuery()
conn.Close()
MessageBox.Show("تمت الإضافة بنجاح", "My Systm", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "خطأ في الإضافة", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
المشروع متعوب عليه باقي بس هذا الشيء للاسف لو كان المشروع بدون اضافة صورة الى لحد الان ماعرفت الطريقة جان من زمان بعته
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - الوليد ☺ - 09-11-14
السلام عليكم ورحمة الله
شوف هذه الطريقة موجودة بالمنتدى
وهي أكثر ترتيباً وتتميز بسهولة مراجعة الكود وأضفت لك طريقة تحويل بيانات الصورة
ملاحظة يجب ترتيب Parameters بنفس الترتيب في جملة الاستعلام حسب ما ذكره الأعضاء
إضافة كلمة Date بعد Value لأداة التاريخ
PHP كود :
Dim conn As New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath() & "\Data.accdb" & ";Persist Security Info=True;Jet OLEDB:Database Password=123")
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Try
Dim sql As String = _ " INSERT INTO [Student] " & _ " ( Student_Name, Student_CPR, Student_Birth, Student_Join, Student_Nation, Student_Sex, Student_D, Student_Place, Student_Address, Student_Sick, Student_Vairus, Student_phone, Student_Dad, Student_mom, Student_Angel, Student_jobmom, Student_jobdad, Student_Famaly, Student_Pic ) " & _ " VALUES " & _ " ( @Student_Name, @Student_CPR, @Student_Birth, @Student_Join, @Student_Nation, @Student_Sex, @Student_D, @Student_Place, @Student_Address, @Student_Sick, @Student_Vairus, @Student_phone, @Student_Dad, @Student_mom, @Student_Angel, @Student_jobmom, @Student_jobdad, @Student_Famaly, @Student_Pic ) "
Dim cmd As New OleDbCommand(sql, conn) cmd.Parameters.AddWithValue("@Student_Name", TextBox1.Text) cmd.Parameters.AddWithValue("@Student_CPR", TextBox10.Text) cmd.Parameters.AddWithValue("@Student_Birth", DateTimePicker1.Value.Date) cmd.Parameters.AddWithValue("@Student_Join", DateTimePicker2.Value.Date) cmd.Parameters.AddWithValue("@Student_Nation", ComboBox2.Text) cmd.Parameters.AddWithValue("@Student_Sex", ComboBox3.Text) cmd.Parameters.AddWithValue("@Student_D", ComboBox1.Text) cmd.Parameters.AddWithValue("@Student_Place", ComboBox4.Text) cmd.Parameters.AddWithValue("@Student_Address", TextBox2.Text) cmd.Parameters.AddWithValue("@Student_Sick", ComboBox5.Text) cmd.Parameters.AddWithValue("@Student_Vairus", TextBox7.Text) cmd.Parameters.AddWithValue("@Student_phon", TextBox3.Text) cmd.Parameters.AddWithValue("@Student_Dad", TextBox4.Text) cmd.Parameters.AddWithValue("@Student_mom", TextBox5.Text) cmd.Parameters.AddWithValue("@Student_Angel", TextBox6.Text) cmd.Parameters.AddWithValue("@Student_jobmom", TextBox8.Text) cmd.Parameters.AddWithValue("@Student_jobdad", TextBox9.Text) cmd.Parameters.AddWithValue("@Student_Famaly", ComboBox6.Text) Using ms As New IO.MemoryStream Me.PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png) cmd.Parameters.AddWithValue("@Student_Pic", ms.ToArray()) End Using
conn.Open() cmd.ExecuteNonQuery() conn.Close()
MessageBox.Show("تمت الإضافة بنجاح", "My Systm", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception MessageBox.Show(ex.Message, "خطأ في الإضافة", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - 0theghost0 - 09-11-14
شكرا على المساعدة لكن طلع لي خطأ
The INSERT INTO statement contains the following unknown field name: 'Student_D'. Make sure you have typed the name correctly, and try the operation again.
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - الوليد ☺ - 09-11-14
السلام عليكم ورحمة الله
الخطأ من عندك، لازم تراجع أسماء الحقول كلها من قاعدة البيانات، لأني وضعت لك الاسماء كما كتبتها أنت
والرسالة تقوم عدم وجود الحقل Student_D فلازم تراجع الاسماء عندك
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - kslawy - 09-11-14
الخطأ في اسم الحقل Student_D ربما يكون الصحيح هو Student_ID بإضافة حرف آي (I) قبل الـ(D) الأخيرة
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - 0theghost0 - 09-11-14
اخي وليد صراحة راجعتهم اكثر من مرة وقمت بكتابتهم من جديد هل يمكنك التأكد لي سوف اقوم برفعه واتمنى الافادة
حمل الملف من الرابط
http://adf.ly/ttggw
RE: كود حفظ الصورة وجده لكن لايعمل بالكامل - الوليد ☺ - 09-11-14
السلام عليكم ورحمة الله
يبدو أن هناك أخطاء بسبب النسق واللصق، فقمت بمسح اسم الحقل من الكود في نص sql وكتابته من جديد فزالت المشكلة،
وتكررت المشكلة في ثلاث أسماء حقول وهي:
Student_D
Student_phone
Student_Famaly
|