تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] خطاء عند عدم رفع الصورة في PictureBox
#1
السلام عليكم اخواني الاعزاء
لدية مشكلة في اضافة صورة  الى قاعدة بيانات SQL من PictureBox
حيث يحدث خطاء اذا لم اقم برفع الصورة مع المعلومات
اريد البرنامج يستمر في حالة عدم وجود صورة علما ان قيمتها في القاعدة NULL
كود :
Private Sub TBsavecustm_Click(sender As Object, e As EventArgs) Handles TBsavecustm.Click

       Dim command As New SqlCommand("insert into Customer(custname,custadress,custwork,custmob1,custmob2,custidno,custidwno,custother,custpic1,custpic2,custpic3) values(@custname,@custadress,@custwork,@custmob1,@custmob2,@custidno,@custidwno,@custother,@custpic1,@custpic2,@custpic3)", SQLcon)

       Dim ms As New MemoryStream
       Piccustm1.Image.Save(ms, Piccustm1.Image.RawFormat)
       Piccustm2.Image.Save(ms, Piccustm2.Image.RawFormat)
       Piccustm3.Image.Save(ms, Piccustm3.Image.RawFormat)



       command.Parameters.Add("@custname", SqlDbType.NVarChar).Value = Texnamecustm.Text
       command.Parameters.Add("@custadress", SqlDbType.NVarChar).Value = Texadresscustm.Text
       command.Parameters.Add("@custwork", SqlDbType.NVarChar).Value = Texworkcustm.Text
       command.Parameters.Add("@custmob1", SqlDbType.NVarChar).Value = Texmob1custm.Text
       command.Parameters.Add("@custmob2", SqlDbType.NVarChar).Value = Texmob2custm.Text
       command.Parameters.Add("@custidno", SqlDbType.NVarChar).Value = Texidcustm.Text
       command.Parameters.Add("@custidwno", SqlDbType.NVarChar).Value = Texwidcustm.Text
       command.Parameters.Add("@custother", SqlDbType.NVarChar).Value = Texothercustm.Text
       command.Parameters.Add("@custpic1", SqlDbType.Image).Value = ms.ToArray()
       command.Parameters.Add("@custpic2", SqlDbType.Image).Value = ms.ToArray()
       command.Parameters.Add("@custpic3", SqlDbType.Image).Value = ms.ToArray()
       ' Dim DT As New DataTable
       '  If Not IsDBNull(DT.Rows(0).Item("@custpic1")) Then
       ' Dim ByteImg As Byte() = DirectCast(DT.Rows(0).Item("@custpic1"), Byte())

       ' End If

       SQLcon.Open()

       If command.ExecuteNonQuery() = 1 Then
           MessageBox.Show("تمت اضافة المعلومات بنجاح..... شكرا")
       Else
           MessageBox.Show("لم يتم الاضافة ... لابد من جود خطاء او نقص معلومات")
       End If

       SQLcon.Close()
       Load_Customer()
       DGVSH.DataSource = dt_Customer
   End Sub
الرد }}}
تم الشكر بواسطة:
#2
معقولة ولا رد خلال 24 ساعة
Sleepy Confused Blush
الرد }}}
تم الشكر بواسطة:
#3
PHP كود :
Private Sub TBsavecustm_Click(ByVal sender As ObjectByVal e As EventArgsHandles TBsavecustm.Click

    Dim command 
As New SqlCommand("insert into Customer(custname,custadress,custwork,custmob1,custmob2,custidno,custidwno,custother,custpic1,custpic2,custpic3) values(@custname,@custadress,@custwork,@custmob1,@custmob2,@custidno,@custidwno,@custother,@custpic1,@custpic2,@custpic3)"SQLcon)

 
   Dim ms1 As New MemoryStream
    If Not IsNothing
(Piccustm1.ImageThen Piccustm1.Image.Save(ms1Piccustm1.Image.RawFormat)

 
   Dim ms2 As New MemoryStream
    If Not IsNothing
(Piccustm2.ImageThen Piccustm2.Image.Save(ms2Piccustm2.Image.RawFormat)

 
   Dim ms3 As New MemoryStream
    If Not IsNothing
(Piccustm3.ImageThen Piccustm3.Image.Save(ms3Piccustm3.Image.RawFormat)

 
   command.Parameters.AddWithValue("@custname"Texnamecustm.Text)
 
   command.Parameters.AddWithValue("@custadress"Texadresscustm.Text)
 
   command.Parameters.AddWithValue("@custwork"Texworkcustm.Text)
 
   command.Parameters.AddWithValue("@custmob1"Texmob1custm.Text)
 
   command.Parameters.AddWithValue("@custmob2"Texmob2custm.Text)
 
   command.Parameters.AddWithValue("@custidno"Texidcustm.Text)
 
   command.Parameters.AddWithValue("@custidwno"Texwidcustm.Text)
 
   command.Parameters.AddWithValue("@custother"Texothercustm.Text)
 
   command.Parameters.AddWithValue("@custpic1"ms1.ToArray)
 
   command.Parameters.AddWithValue("@custpic2"ms2.ToArray)
 
   command.Parameters.AddWithValue("@custpic3"ms3.ToArray)
    
' Dim DT As New DataTable
    '  
If Not IsDBNull(DT.Rows(0).Item("@custpic1")) Then
    
' Dim ByteImg As Byte() = DirectCast(DT.Rows(0).Item("@custpic1"), Byte())

    ' 
End If

 
   SQLcon.Open()

 
   If command.ExecuteNonQuery() = 1 Then
        MessageBox
.Show("تمت اضافة المعلومات بنجاح..... شكرا")
 
   Else
        MessageBox
.Show("لم يتم الاضافة ... لابد من جود خطاء او نقص معلومات")
 
   End If

 
   SQLcon.Close()
 
   Load_Customer()
 
   DGVSH.DataSource dt_Customer
End Sub
Private Sub DGVSH_DataError(ByVal sender As ObjectByVal e As DataGridViewDataErrorEventArgsHandles DGVSH.DataError
    
'اترك هذا الحدث كما هو فارغ ولا تحذفه
End Sub 
الرد }}}
تم الشكر بواسطة: ابو ملاك الخبير
#4
(28-02-18, 04:16 AM)طالب برمجة كتب :
PHP كود :
Private Sub TBsavecustm_Click(ByVal sender As ObjectByVal e As EventArgsHandles TBsavecustm.Click

    Dim command 
As New SqlCommand("insert into Customer(custname,custadress,custwork,custmob1,custmob2,custidno,custidwno,custother,custpic1,custpic2,custpic3) values(@custname,@custadress,@custwork,@custmob1,@custmob2,@custidno,@custidwno,@custother,@custpic1,@custpic2,@custpic3)"SQLcon)

 
   Dim ms1 As New MemoryStream
    If Not IsNothing
(Piccustm1.ImageThen Piccustm1.Image.Save(ms1Piccustm1.Image.RawFormat)

 
   Dim ms2 As New MemoryStream
    If Not IsNothing
(Piccustm2.ImageThen Piccustm2.Image.Save(ms2Piccustm2.Image.RawFormat)

 
   Dim ms3 As New MemoryStream
    If Not IsNothing
(Piccustm3.ImageThen Piccustm3.Image.Save(ms3Piccustm3.Image.RawFormat)

 
   command.Parameters.AddWithValue("@custname"Texnamecustm.Text)
 
   command.Parameters.AddWithValue("@custadress"Texadresscustm.Text)
 
   command.Parameters.AddWithValue("@custwork"Texworkcustm.Text)
 
   command.Parameters.AddWithValue("@custmob1"Texmob1custm.Text)
 
   command.Parameters.AddWithValue("@custmob2"Texmob2custm.Text)
 
   command.Parameters.AddWithValue("@custidno"Texidcustm.Text)
 
   command.Parameters.AddWithValue("@custidwno"Texwidcustm.Text)
 
   command.Parameters.AddWithValue("@custother"Texothercustm.Text)
 
   command.Parameters.AddWithValue("@custpic1"ms1.ToArray)
 
   command.Parameters.AddWithValue("@custpic2"ms2.ToArray)
 
   command.Parameters.AddWithValue("@custpic3"ms3.ToArray)
 
   ' Dim DT As New DataTable
    ' 
 If Not IsDBNull(DT.Rows(0).Item("@custpic1")) Then
    
' Dim ByteImg As Byte() = DirectCast(DT.Rows(0).Item("@custpic1"), Byte())

    ' 
End If

 
   SQLcon.Open()

 
   If command.ExecuteNonQuery() = 1 Then
        MessageBox
.Show("تمت اضافة المعلومات بنجاح..... شكرا")
 
   Else
        MessageBox
.Show("لم يتم الاضافة ... لابد من جود خطاء او نقص معلومات")
 
   End If

 
   SQLcon.Close()
 
   Load_Customer()
 
   DGVSH.DataSource dt_Customer
End Sub
Private Sub DGVSH_DataError(ByVal sender As ObjectByVal e As DataGridViewDataErrorEventArgsHandles DGVSH.DataError
    
'اترك هذا الحدث كما هو فارغ ولا تحذفه
End Sub 



كلمات الشكر لا تكفيك ابدا
شكرا لك من القلب
الرد }}}
تم الشكر بواسطة: طالب برمجة



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم