23-10-17, 12:37 AM
السلام عليكم
الرجاء تصحيح كود حفظ الصور بقاعدة البيانات SQL SERVER
الكود المستخدم
Dim addteo As String = MsgBox("هل حقأ ترغب اضافة البيانات ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "تأكيد عملية اضافة البيانات")
If addteo = vbYes Then
Cmd = New OleDbCommand(" Insert Into invest (patient_Name,[DATE],investigation_name,Report,eye,photo)
values ('" & textname.Text & "','" & Trim(Textdate.Text) & "','" & TEXTINVE1.Text & "','" & TextREPORT1.Text & "','" & texteye1.Text & "',@photo)", Con)
Dim ms1 As New MemoryStream()
PBOX1.BackgroundImage.Save(ms1, PBOX1.BackgroundImage.RawFormat)
Dim picture1 As Byte() = ms1.GetBuffer()
Dim p As New OleDbParameter("@photo", SqlDbType.Image)
p.Value = picture1
Cmd.Parameters.Add(p)
Cmd.ExecuteNonQuery()
Con.Close()
MsgBox("تمت عملية حفظ البيانات بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
cler()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
تظهر رساله خطاء object reference not set to an instance of an object
تم استخدام كود اخر
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim open As New OpenFileDialog
If open.ShowDialog = DialogResult.OK Then
pbox.Image = Image.FromFile(open.FileName)
End If
Dim ms1 As New MemoryStream()
pbox.Image.Save(ms1, pbox.Image.RawFormat)
Dim arrimg() As Byte = ms1.GetBuffer
ms1.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Con.Open()
Dim sqlc As New OleDbCommand
sqlc.Connection = Con
sqlc.CommandText = "insert into invest (patient_Name,[DATE],investigation_name,Report,eye,photo)" & "values('" & textname.Text & "','" & Trim(Textdate.Text) & "','" & TEXTINVE1.Text & "','" & TextREPORT1.Text & "','" & texteye1.Text & "'," & "@img" & ")"
sqlc.Parameters.Add(New OleDbParameter("@img", SqlDbType.Image)).Value = arrimg
sqlc.ExecuteNonQuery()
Con.Close()
MsgBox("تمت عملية حفظ البيانات بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
وايضا يظهر الخطاء must declare the scalar variable "@img"
برجاء المساعدة
الرجاء تصحيح كود حفظ الصور بقاعدة البيانات SQL SERVER
الكود المستخدم
Dim addteo As String = MsgBox("هل حقأ ترغب اضافة البيانات ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "تأكيد عملية اضافة البيانات")
If addteo = vbYes Then
Cmd = New OleDbCommand(" Insert Into invest (patient_Name,[DATE],investigation_name,Report,eye,photo)
values ('" & textname.Text & "','" & Trim(Textdate.Text) & "','" & TEXTINVE1.Text & "','" & TextREPORT1.Text & "','" & texteye1.Text & "',@photo)", Con)
Dim ms1 As New MemoryStream()
PBOX1.BackgroundImage.Save(ms1, PBOX1.BackgroundImage.RawFormat)
Dim picture1 As Byte() = ms1.GetBuffer()
Dim p As New OleDbParameter("@photo", SqlDbType.Image)
p.Value = picture1
Cmd.Parameters.Add(p)
Cmd.ExecuteNonQuery()
Con.Close()
MsgBox("تمت عملية حفظ البيانات بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
cler()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
تظهر رساله خطاء object reference not set to an instance of an object
تم استخدام كود اخر
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim open As New OpenFileDialog
If open.ShowDialog = DialogResult.OK Then
pbox.Image = Image.FromFile(open.FileName)
End If
Dim ms1 As New MemoryStream()
pbox.Image.Save(ms1, pbox.Image.RawFormat)
Dim arrimg() As Byte = ms1.GetBuffer
ms1.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Con.Open()
Dim sqlc As New OleDbCommand
sqlc.Connection = Con
sqlc.CommandText = "insert into invest (patient_Name,[DATE],investigation_name,Report,eye,photo)" & "values('" & textname.Text & "','" & Trim(Textdate.Text) & "','" & TEXTINVE1.Text & "','" & TextREPORT1.Text & "','" & texteye1.Text & "'," & "@img" & ")"
sqlc.Parameters.Add(New OleDbParameter("@img", SqlDbType.Image)).Value = arrimg
sqlc.ExecuteNonQuery()
Con.Close()
MsgBox("تمت عملية حفظ البيانات بنجاح", MsgBoxStyle.Exclamation, "تأكيد عملية الحفظ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
وايضا يظهر الخطاء must declare the scalar variable "@img"
برجاء المساعدة